MongoDB check exists in array
collection 'books':
array (
'_id' => new MongoId("4e242b0ea5bb1bb00b000000"),
'book' =>
array (
'0' => 1,
'1' => 2,
'开发者_C百科2' => 3,
'3' => 14,
'4' => 15,
),
'book_count' => 5,
'user_name' => 'john',
)
How can I check where 'some book' in an array 'book'?
is this only way to check ?
db.books.count({user_name:'john', book:1})
Yes, although the following would be faster
db.books.find({user_name:'john', book:1}).limit(1) != null
精彩评论