Getting Documents from a Collection

One of the tasks that you commonly need to perform on data stored in a MongoDB database is retrieving one or more documents. For example, consider product information for products on a commercial website. The information is stored once but retrieved many times.

The retrieval of data sounds fairly simple, but it can become quite complex as you need to also filter, sort, limit, and aggregate the results. In fact, Chapter 15, “Accessing MongoDB Documents from Node.js,” is devoted to the complexities of retrieving data.

This section introduces you to the simple basics of the find() and findOne() methods of the Collection object to make it easier to understand the code examples in this chapter. The syntax for the ...

Get Node.js, MongoDB, and AngularJS Web 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.