Find document with array that contains a specific value

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

    In case that the array contains objects for example if favouriteFoods is an array of objects of the following:

    {
      name: 'Sushi',
      type: 'Japanese'
    }
    

    you can use the following query:

    PersonModel.find({"favouriteFoods.name": "Sushi"});
    

提交回复
热议问题