How to find document with array that contains a specific value?

Technology CommunityCategory: MongoDBHow to find document with array that contains a specific value?
VietMX Staff asked 3 years ago
Problem

You have this schema:

person = {
    name : String,
    favoriteFoods : Array
}

where the favoriteFoods array is populated with strings. How can I find all persons that have sushi as their favorite food using MongoDB?

Consider:

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