Skip to content

Instantly share code, notes, and snippets.

@adrianmilne
Created August 2, 2013 13:58
Show Gist options
  • Save adrianmilne/6140092 to your computer and use it in GitHub Desktop.
Save adrianmilne/6140092 to your computer and use it in GitHub Desktop.
Example MongoDB Build Script for a simple Library Database
print("Starting MongoDB Library Database Build Script")
print("Creating Libary Database")
var libraryDB = db.getSiblingDB("library")
print("Creating Book Collection")
libraryDB.createCollection("book")
print("Creating index on 'type' field")
libraryDB.book.ensureIndex({type:1})
print("Populating Book Data")
libraryDB.book.insert({name:"The Lord Of The Rings",author:"J.R.R. Tolkien",type:"Fantasy"})
libraryDB.book.insert({name:"The Silmarillion",author:"JRR Tolkien",type:"Fantasy"})
libraryDB.book.insert({name:"Dune",author:"Frank Herbert",type:"Sci-Fi"})
print("Finished MongoDB Library Database Build Script")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment