Use AND - operator in the find method

后端 未结 1 1076
旧时难觅i
旧时难觅i 2021-01-26 22:52

I have a collection with the array field. If I want to find all documents with specific tag I use next query:

db.Bookmarks.find({tags : {$regex: \"bbb\"}})
         


        
1条回答
  •  梦毁少年i
    2021-01-26 22:57

    You can use the $all query operator to do this:

    db.Bookmarks.find({tags: {$all: ['bbb', 'ccc']}})
    

    You can use regular expressions as well. To include tags that start with c instead:

    db.Bookmarks.find({tags: {$all: ['bbb', /^c/]}})
    

    0 讨论(0)
提交回复
热议问题