开发者

MongoDB check exists in array

开发者 https://www.devze.com 2023-03-21 06:02 出处:网络
collection \'books\': array ( \'_id\' => new MongoId(\"4e242b0ea5bb1bb00b000000\"), \'book\' => 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 
0

精彩评论

暂无评论...
验证码 换一张
取 消