Database Reference
In-Depth Information
When you define a variable in the shell (for example, document = ( { ... } ) ),
the contents of the variable will be printed out immediately.
Note
> db.media.insert(document)
Line breaks can also be used while typing in the shell. This can be convenient if you
are writing a rather lengthy document, as in this example:
> document = ( { "Type" : "Book",
..."Title" : "Definitive Guide to MongoDB 2nd ed., The",
..."ISBN" : "978-1-4302-5821-6",
..."Publisher" : "Apress",
..."Author" : ["Hows, David", Plugge, Eelco", "Membrey, Peter"," "Hawkins, Tim"]
...} )
> db.media.insert(document)
As mentioned, the other option is to insert your data directly through the shell,
without defining the document first. You can do this by invoking the insert function
immediately, followed by the document's contents:
> db.media.insert( { "Type" : "CD", "Artist" : "Nirvana", "Title" :
"Nevermind" })
Or you can insert the data while using line breaks, as before. For example, you can
expand the preceding example by adding an array of tracks to it. Pay close attention to
how the commas and brackets are used in the following example:
> db.media.insert( { "Type" : "CD",
..."Artist" : "Nirvana",
..."Title" : "Nevermind",
... "Tracklist" : [
... {
... "Track" : "1",
... "Title" : "Smells Like Teen Spirit",
... "Length" : "5:02"
... },
... {
... "Track" : "2",
... "Title" : "In Bloom",
... "Length" : "4:15"
... }
... ]
...}
... )
 
Search WWH ::




Custom Search