Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11864

$in operator fails if document field name is "query"

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.4.8
    • Component/s: Querying
    • None
    • Environment:
      Mac OS X or Linux, mongodb 2.4.8, mongo 2.4.8
    • Major Change
    • ALL

      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 }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            innin MIkhail Kyurshin
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: