From the course: MongoDB Python Developer Associate Cert Prep
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Returning specific data from a query in MongoDB
From the course: MongoDB Python Developer Associate Cert Prep
Returning specific data from a query in MongoDB
- Welcome back, team. In this video, we'll learn how to return selected fields from a query. By default, queries in MongoDB return all fields in their matching documents. Sometimes, however, an application will only use data from a subset of these fields. In this case, we can limit the amount of data sent from MongoDB and improve our bandwidth performance by selecting which fields are returned. We refer to this process as projection and it can be used in most find queries. Let's see how we can use projections in a query. In these examples, we'll be working with the training database again but we'll be querying the inspections collection. In our inspection collection, we do have quite a few documents so let's take a look at one using the find one method. I'll go ahead and do a db.inspections.findOne. As we can see, this document has quite a few fields on it that we might not want to see all of at the same time. In…