mongodb 通过数组某一元素查询

> db.test.insert({ arr: [ 1, 2, 3, 4, 5] })
WriteResult({ "nInserted" : 1 })

> db.test.insert({ arr: [ 5, 6, 7, 8, 9 ] })
WriteResult({ "nInserted" : 1 })

> db.test.find({ arr : { $in : [ 3 ] } })
{ "_id" : ObjectId("5779d5b99f113cca8e7002c1"), "arr" : [ 1, 2, 3, 4, 5 ] }

> db.test.find({ arr : { $in : [ 5 ] } })
{ "_id" : ObjectId("5779d5b99f113cca8e7002c1"), "arr" : [ 1, 2, 3, 4, 5 ] }
{ "_id" : ObjectId("5779d6879f113cca8e7002c2"), "arr" : [ 5, 6, 7, 8, 9 ] }

> db.test.find({ arr : { $in : [ 3, 4, 5 ] } })
{ "_id" : ObjectId("5779d5b99f113cca8e7002c1"), "arr" : [ 1, 2, 3, 4, 5 ] }
{ "_id" : ObjectId("5779d6879f113cca8e7002c2"), "arr" : [ 5, 6, 7, 8, 9 ] }

> db.test.find({ arr: 5 })
{ "_id" : ObjectId("5779d5b99f113cca8e7002c1"), "arr" : [ 1, 2, 3, 4, 5 ] }
{ "_id" : ObjectId("5779d6879f113cca8e7002c2"), "arr" : [ 5, 6, 7, 8, 9 ] }
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s