[SERVER-20127] Operator $or(query) and operator $(projection) don't work together. Created: 26/Aug/15  Updated: 08/Oct/15  Resolved: 08/Oct/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.0.4
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Roman Assignee: Wan Bachtiar
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

QUERY:

db.users.find({
                            $or: [
                                {
                                        _id: senderId,
                                        "_contacts._profile_id": recipientId
                                },
                                {
                                    _id: recipientId,
                                    "_contacts._profile_id": senderId
                                }
                            ]
},
{
"_contacts.$": 1
})

ERROR:
BadValue positional operator (_contacts.$) requires corresponding field in query specifier","code":17144} must be equivalent to undefined



 Comments   
Comment by Wan Bachtiar [ 08/Oct/15 ]

Hi Roman,

Thanks for the report.

This behaviour is mentioned in the MongoDB documentation as a limitation of positional projection: http://docs.mongodb.org/manual/reference/operator/projection/positional/#array-field-limitation

The query document can only contain a single condition on the array field being projected. In your case, the $or operator states multiple conditions on the array field, which could override each other internally and lead to undefined behaviour.

Regards,

Wan.

Generated at Thu Feb 08 03:53:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.