Loading...
Loading...
Combining a positional operator in the projection with some other array dotted field returns: "BadValue: positional operator element mismatch" Example: db.collection.find({ "my_array" : { $elemMatch : { "key1" : "value1", "key2" : "value2" } } }, { "my_array.$" : 1, "some_other_array.other_field" : 1 }) returns the error message. db.collection.find({ "my_array" : { $elemMatch : { "key1" : "value1", "key2" : "value2" } } }, { "my_array.$" : 1 }) returns the expected result. According to the docs at: https://docs.mongodb.com/manual/reference/operator/projection/positional/ Only one array field, the one being limited with the $ projection operator, should appear in the query document. Additional array fields in the query document may lead to undefined behavior But there is no similar limit on the projection document.
mark.agarunov commented on Thu, 4 May 2017 20:41:12 +0000: Hello Marmor, We haven’t heard back from you for some time, so I’m going to mark this ticket as resolved. If this is still an issue for you, please provide additional information and we will reopen the ticket. Thanks, Mark ramon.fernandez commented on Fri, 31 Mar 2017 00:01:56 +0000: Marmor, in what version of MongoDB are you seeing this behavior? marmor commented on Thu, 30 Mar 2017 09:25:47 +0000: A workaround is to use $elemMatch in the projection, and copy the same element query document used in the query for the projection, that works but cumbersome. Also, this workaround doesn't help if you want a specific field within the element, such as: { "my_array.$.key1" : 1, "other_array.key1" : 1 }
1. Create a collection with documents containing to array fields with inner documents in each. 2. Query for: db.collection.find({ "array1" : { $elemMatch : { "key1" : "value1", "key2" : "value2" } } }, { "array1.$" : 1, "array2.other_field" : 1 })
Click on a version to see all relevant bugs
MongoDB Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.