Quantcast
Channel: CodeSection,代码区,数据库(综合) - CodeSec
Viewing all articles
Browse latest Browse all 6262

mongodb 通过数组某一元素查询

$
0
0
> 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 ] }

Viewing all articles
Browse latest Browse all 6262

Trending Articles