Book Image

Learning Node.js for Mobile Application Development

Book Image

Learning Node.js for Mobile Application Development

Overview of this book

Table of Contents (21 chapters)
Learning Node.js for Mobile Application Development
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
14
Creating an E-Commerce Application Using the Ionic Framework
Index

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 that we want to look up a given product by ID. We select an ID from the earlier example at random and see what we end up with. Remember that the ID will be different on your own machine. So, you will need to select the one that is associated with...