[SERVER-11864] $in operator fails if document field name is "query" Created: 26/Nov/13  Updated: 10/Dec/14  Resolved: 26/Nov/13

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

Type: Bug Priority: Minor - P4
Reporter: MIkhail Kyurshin Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS X or Linux, mongodb 2.4.8, mongo 2.4.8


Issue Links:
Duplicate
duplicates SERVER-8025 shell supports "query" works as a met... Closed
duplicates SERVER-9812 User query is interpreted incorrectly... Closed
Backwards Compatibility: Major Change
Operating System: ALL
Participants:

 Description   

If document has field with name "query", querying this field with "$in" operator fails. Here are steps to reproduce:

test.js

db.test.insert({q: 'test', i: 1});
db.test.insert({q: 'shmest', i: 2});
db.test.insert({q: 'quest', i: 3});
db.test.ensureIndex({q: 1});
db.test.find({q: {$in: ['test', 'shmest']}});
//{ "_id" : ObjectId("5294c0b2c32bf844e1f74e52"), "q" : "shmest", "i" : 2 }
//{ "_id" : ObjectId("5294c09fc32bf844e1f74e51"), "q" : "test", "i" : 1 }
 
db.test.count({q: {$in: ['test', 'shmest']}});
//2
 
db.test.remove();
 
db.test.insert({query: 'test', i: 1});
db.test.insert({query: 'shmest', i: 2});
db.test.insert({query: 'quest', i: 3});
db.test.ensureIndex({query: 1});
 
db.test.find({query: {$in: ['test', 'shmest']}});
//query fails: no response (and on large collection it takes a lot of time as if there's no index)
 
db.test.count({query: {$in: ['test', 'shmest']}});
//2
 
db.test.find({query: 'test'});
//{ "_id" : ObjectId("5294c166c32bf844e1f74e55"), "query" : "test", "i" : 1 }
 
//db.test.find({query: 'shmest'});
{ "_id" : ObjectId("5294c166c32bf844e1f74e56"), "query" : "shmest", "i" : 2 }
 
db.test.find({$or: [{query: 'test'}, {query: 'shmest'}]});
//{ "_id" : ObjectId("5294c166c32bf844e1f74e55"), "query" : "test", "i" : 1 }
//{ "_id" : ObjectId("5294c166c32bf844e1f74e56"), "query" : "shmest", "i" : 2 }



 Comments   
Comment by MIkhail Kyurshin [ 26/Nov/13 ]

Thank you, Jason
I was looking for existing issue, but did not find one, so decided to create. Sorry for duplicate

Comment by J Rassi [ 26/Nov/13 ]

This is a known issue with the shell. SERVER-8025 is tracking this issue's progress. See also comments at SERVER-9812.

As a workaround, you should run instead:

db.test.find({$query: {query: {$in: ['test', 'shmest']}}});

You will need to do this for any find with the shell on a top-level field called "query" where the predicate is not a simple equality match.

Resolving this issue as a dup of SERVER-8025; feel free to re-open if you have further questions.

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