0

When I query like this :

collection.find({ "position": { $in: [ 1, 2 ] } }).toArray()....

I get the right result, when I use $and or $or , for example:

collection.find({ $or: [ { "position": 1 }, { "position": 2 }  ] }).toArray()...

I always get the empty result

EDIT: when trying to query in console I get:

> db.foo.find({"position":{$in:[1,2]}})
{ "name" : "Jon Doe", "position" : 1, "arrival" : "8:00", "_id" :ObjectId("512e2ed286d19b9e4d000001") }
{ "name" : "Jack Smith", "position" : 2, "arrival" : "10:00", "_id" : ObjectId("512e2ed286d19b9e4d000007") }

db.foo.find( { $or : [{"position":1},{"position":2}]} )

  //nothing here

From this, I get the impression, my code is OK and the problem is elsewhere...

slezadav
  • 6,104
  • 7
  • 40
  • 61

2 Answers2

2

Query Something like this,

> db.foo.find({"x":{$in:[1,2]}})
{ "_id" : ObjectId("513046c8ec1e5e38449f1789"), "x" : 1, "y" : 2 }
{ "_id" : ObjectId("5130cdfdf8378ccc2005bcf2"), "x" : 2 }
> 

> db.foo.find( { $or : [{"x":1},{"x":2}]} )
{ "_id" : ObjectId("513046c8ec1e5e38449f1789"), "x" : 1, "y" : 2 }
{ "_id" : ObjectId("5130cdfdf8378ccc2005bcf2"), "x" : 2 }
> 
Srivatsa N
  • 2,291
  • 4
  • 21
  • 36
2

You need to use newer version of Mongo. It is supported for version > 1.6.

See the changelog.

Michal
  • 15,429
  • 10
  • 73
  • 104