Find document with array that contains a specific value

前端 未结 10 1334
猫巷女王i
猫巷女王i 2020-11-22 04:06

If I have this schema...

person = {
    name : String,
    favoriteFoods : Array
}

... where the favoriteFoods array is popula

10条回答
  •  再見小時候
    2020-11-22 04:31

    There is no $contains operator in mongodb.

    You can use the answer from JohnnyHK as that works. The closest analogy to contains that mongo has is $in, using this your query would look like:

    PersonModel.find({ favouriteFoods: { "$in" : ["sushi"]} }, ...);
    

提交回复
热议问题