mongoose query array code example

Example 1: Find document with array that contains a specific value

As favouriteFoods is a simple array of strings, you can just query that field directly:

PersonModel.find({ favouriteFoods: "sushi" }, ...);

model:
person = {
    name : String,
    favoriteFoods : Array
}

Example 2: mongodb find array with element

// Finds all documents that have a property named "tags"
// which has at least one array element matching "red"
db.inventory.find( { tags: "red" } )

Example 3: mongodb array field contains

db.inventory.find( { tags: { $all: ["red", "blank"] } } )

Example 4: mongoose query using an arry

var query = PUser.find({'userID': {$in:array}});

Example 5: mongo array

db.inventory.find( { tags: ["red", "blank"] } )

Tags:

Misc Example