Querying MongoDB
We are now familiar with the overall structure of data storage in MongoDB as well as how to insert and perform some rudimentary retrieval using the find()
method. Here, we will look at the more advanced usage of find()
in order to do some more fine-grained data retrieval.
Searching by ID
One of the most common operations on a MongoDB instance is lookups based on ID. As you may recall, every document in a database has a unique _id
field, and MongoDB makes it easy to find documents using it.
Let's try this out! Start your Mongo shell and open the OrderBase
database again. If you closed it after the last example, you can reopen the database by issuing the following command:
> use OrderBase
Once the database has been selected, let's say ...
Get Learning Node.js for Mobile Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.