In this particular case, everything works fine, except when for fields field1 , field2 , and field1 is part of field2 .
Example:
> db.mycoll.findOne() { "_id" : 1, "data" : { "amounts" : { "dollar" : 20, "euro" : 18 }, "item" : "toy", "sale" : false } } // works well > db.mycoll.findOne({"_id":1},{ "data.amounts.dollar":1 }) { "_id" : 1, "data" : { "amounts" : { "dollar" : 20 } } } // here "data" is root of "data.amounts.dollar" and "data.amounts.euro" // takes preference, how to query for "data", so // that all subfields of data are // returned > db.mycoll.findOne({"_id":1},{ "data":1 , "data.amounts.dollar":1 }) { "_id" : 1, "data" : { "amounts" : { "dollar" : 20 } } }
Expected Result:
{ "_id" : 1, "data" : { "amounts" : { "dollar" : 20, "euro" : 18 }, "item" : "toy", "sale" : false } }
Yes, you can format the subfields on the program side and send the root field to the mongodb request, but my question is whether this is possible on the request side without Javascript.
source share