Find document with array that contains a specific value

前端 未结 10 1469
猫巷女王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:30

    I know this topic is old, but for future people who could wonder the same question, another incredibly inefficient solution could be to do:

    PersonModel.find({$where : 'this.favouriteFoods.indexOf("sushi") != -1'});
    

    This avoids all optimisations by MongoDB so do not use in production code.

提交回复
热议问题