Getting Data with Queries
Explore how to query data effectively in MongoDB using Meteor.js. Understand the structure of embedded documents, use dot notation, and apply common query operators. Practice fetching data with Meteor's reactive API, including options like sort, limit, and skip to control query results.
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:
db.collectionName.find()
Or:
db.collectionName.findOne()
Meteor MongoDB API for ...