Database Reference
In-Depth Information
Inserting the { Title : 1 } information specifies that only the information from the title field should be
returned. The results are sorted and presented to you in ascending order.
Note
the ascending order is based upon the insertion order of the document.
You can also accomplish the opposite: inserting { Type : 0 } retrieves a list of all items you have stored from
Nirvana, showing all information except for the Type field.
Note
the _id field will by default remain visible, unless you explicitly ask it not to show itself.
Take a moment to run the revised query with the { Title : 1 } insertion; no unnecessary information is
returned at all. This saves you time because you see only the information you want. It also spares your database the
time required to return unnecessary information.
Using the Dot Notation
When you start working with more complex document structures such as documents containing arrays or embedded
objects, you can begin using other methods for querying information from those objects as well. For example, assume
you want to find all CDs that contain a specific song you like. The following code executes a more detailed query:
> db.media.find( { "Tracklist.Title" : "In Bloom" } )
{ "_id" : "ObjectId("4c1a86bb2955000000004076"), "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"
}
] }
Using a period [ . ] after the key's name tells your find function to look for information embedded in your
documents. Things are a little simpler when working with arrays. For example, you can execute the following query
if you want to find a list of topics written by Peter Membrey:
> db.media.find( { "Author" : "Membrey, Peter" } )
{ "_id" : "ObjectId("4c1a8a56c603000000007ecb"), "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"] }
 
 
Search WWH ::




Custom Search