Getting Data with Queries

Learn how to query and filter MongoDB collections.

Embedded document

A document is like a row of data. It consists of a key-value pair of the data. An embedded document is a document with a value that’s a field in another document.

  {
     "name" : "John Doe"
     "age" : 24,
     "education" : {
        "primary": "St Lukes",
        "secondary": "Federal Govt College",
        "tertiary" : "University of Ilorin"
    }
  }

The education field of the top document (object) above is an embedded document. Dot notation is used when querying for an embedded document.

What’s a query?

A query in MongoDB is the way data is retrieved from the database. A query statement could be used to retrieve all data in a collection, or it can contain criteria that restricts the retrieved data.

Query structure in MongoDB

A query in MongoDB usually takes the form of the following:

...