0

私がこのように質問するとき:

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

$andまたはを使用すると、正しい結果が得られます$or。たとえば、次のようになります。

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

私はいつも空の結果を得る

編集:コンソールでクエリを実行しようとすると、次のようになります。

> 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

これから、私は印象を受けます、私のコードは大丈夫です、そして問題は他の場所にあります...

4

2 に答える 2

2

このようなクエリ、

> 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 }
> 
于 2013-03-01T15:54:16.137 に答える
2

新しいバージョンのMongoを使用する必要があります。バージョン>1.6でサポートされています。

変更ログを参照してください。

于 2013-03-01T16:17:23.093 に答える