coiso
coiso

Reputation: 7479

$elemMatch returning false positive

my query:

{ 'objects.item.opts1.opts2': { '$elemMatch': [ { name: 'false' } ] } }

returns: any item that has anything in the array opts2, even if I change 'name' to some field that is not present the result will always be the same

mongoose schema:

var MySchema = new Schema({
    objects: {
        item: {
            opts1: [{
                opts2: [{
                    name:   { type: String },
                }]
            }],      
        },
});

Upvotes: 0

Views: 83

Answers (1)

Shreyance Jain
Shreyance Jain

Reputation: 944

Use following wihout array in $elemMatch....

{ 'objects.item.opts1.opts2': { '$elemMatch': { name: 'false' } } }

Upvotes: 4

Related Questions