I want to execute map-reduce operation on specific documents from MongoDB.
Let's say, we have this "document":
{
a: {
b: {
c:{}
}
}
}
I want to select only those documents, that have an a.b.c field. From this documentation page I know, that $exists operator can help.
To check, that a exists I should use:
query: {
a: { $exists : true }
}
But what query should I use for nested field, described before?
query: {
//?
}
Accessing embedded/nested documents – In MongoDB, you can access the fields of nested/embedded documents of the collection using dot notation and when you are using dot notation, then the field and the nested field must be inside the quotation marks.
To remove an element from a doubly-nested array in MongoDB document, you can use $pull operator. Now field "UserZipCode": "20010" has been removed from a doubly-nested array.
You can select a single field in MongoDB using the following syntax: db. yourCollectionName. find({"yourFieldName":yourValue},{"yourSingleFieldName":1,_id:0});
Use the $elemMatch operator to query embedded documents. Use conditional operators to query embedded documents. Use Visual Query Builder to query embedded documents.
This isn't related to the fact of using map-reduce.
query: {
'a.b.c' : { $exists : true }
}
So is a standard query on an embedded document: http://docs.mongodb.org/manual/tutorial/query-documents/#embedded-documents
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