How do I project the author's first name using a MongoDB query
{
name: "Wings Of Fire",
author:
{
first: "Abdul",
last: "Kalam"
}
}
Adding a new projection queryIn the MongoDB integration, click the Collections to Replicate tab. Navigate to the desired collection. Click the checkbox to the left of the collection to set it to replicate.
In MongoDB, projection means selecting only the necessary data rather than selecting whole of the data of a document. If a document has 5 fields and you need to show only 3, then select only 3 fields from them.
You can select a single field in MongoDB using the following syntax: db. yourCollectionName. find({"yourFieldName":yourValue},{"yourSingleFieldName":1,_id:0});
You can use dot notation in the field selector to project subdocument fields. In the shell:
db.test.find({}, {'author.first': 1})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With