EDWARD'S LECTURE NOTES:
More notes at http://tanguay.info/learntracker
C O U R S E 
MongoDB for Node.js Developers
Andrew Erlichson, MongoDB University
https://university.mongodb.com/courses/10gen/M101JS/2014_June/about
C O U R S E   L E C T U R E 
More Querying in MongoDB
Notes taken on June 14, 2014 by Edward Tanguay
•
sometimes you want a union of operators
•
use $or
•
the shell helps you with this by highlighting
•
$and is also available, but there is an easier way to do it in most cases except those are are very complicated
•
the following is the case because JavaScript object in the shell will simply replace the second "score" with the first
•
polymorphism query matching
•
in the statement db.accounts.find( { favorites : "pretzels" } )
•
if favorites is a string, it looks for a match, if an array, then looks if it is contained in the array
•
this is a common idiom when using mongo
•
but only the top level of the array, no recursing to find a particular field with a particular value
•
$all operator
•
find all documenst which have all items in a list
•
db.accounts.find( { favorites : { $all : ["pretzels","beer" ] }} )
•
$in operator
•
find all documenst which have any items in a list
•
db.accounts.find( { favorites : { $in : ["pretzels","beer" ] }} )
•
nested documents
•
when searching for embedded data, order is important, so it is important to be consistent
•
even if you just search for one field db.users.find( { email : { work : "richard@10gen.com" } } ) then it will not find it, but there is another way
•
cursors
•
cursor object has many methods
•
hasNext()
•
next()
•
use these to step through
•
you don't do this much from the shell, but from a programming language, e.g. python
•
limit(5)
•
you specify this, and then perform a query:
•
sort()
•
first set sort, then perform query
•
you can combine them:
•
cur.sort( { name : -1 } ).limit(3); null;
•
skip()
•
example to list 3
•
cur.sort( { name : -1 } ).limit(3).skip(2); null;
•
this means to skip the first two in that ordering, and still show three
•
processed in this order: sort, skip, limit
•
counting:
•
interate through results with it
•
db.scores.count({ count : "exam" })