How does Query.prototype.all() work in Mongoose ? Last Updated : 12 Mar, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The Query.prototype.all() specifies an $all query condition. User can specify all values that has to be matched in an array passed as parameter. Syntax: Query.prototype.all() Parameters: This function has two parameter, path and array of values.Return Value: This function returns Query Object.Installing mongoose : npm install mongoose After installing the mongoose module, you can check your mongoose version in command prompt using the command. npm mongoose --version After that, you can just create a folder and add a file for example, index.js as shown below. Database: The sample database used here is shown below: Example 1: index.js const mongoose = require('mongoose'); // Database connection mongoose.connect('mongodb://127.0.0.1:27017/geeksforgeeks', { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true }); // User model const User = mongoose.model('User', { name: { type: String }, age: { type: Number } }); User.find().all('name',['Gourav']) .exec(function(error, result) { if (error) { console.log(error) } else { console.log(result) } }); The project structure will look like this: Run index.js file using below command: node index.js Output: [ { _id: 5ebb9129a99bde77b2efb809, name: 'Gourav', age: 10, __v: 0 } ] Example 2: index.js const express = require('express'); const mongoose = require('mongoose'); const app = express() // Database connection mongoose.connect('mongodb://127.0.0.1:27017/geeksforgeeks', { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true }); // User model const User = mongoose.model('User', { name: { type: String }, age: { type: Number } }); User.find().all('age', [25]) .exec(function(error, result) { if (error) { console.log(error) } else { console.log(result) } }); app.listen(3000, function(error ){ if(error) console.log(error) console.log("Server listening on PORT 3000") }) The project structure will look like this: Run index.js file using below command: node index.js Output: Server listening on PORT 3000 [ { _id: 5ebc3669a99bde77b2efb9ba, name: 'Lalit', age: 25, __v: 0 } ] Reference: https://mongoosejs.com/docs/api/query.html#query_Query-all Comment More infoAdvertise with us Next Article How does Query.prototype.all() work in Mongoose ? G gouravhammad Follow Improve Article Tags : Web Technologies Node.js Mongoose Similar Reads How does Query.prototype.and() work in Mongoose ? The Query.prototype.and() specifies arguments for a $and condition. The array parameter contains all the conditions that has to be matched.Syntax:  Query.prototype.and() Parameters: This function has one array parameter i.e. an array of conditions.Return Value: This function returns Query Object.In 2 min read How does Query.prototype.cast() work in Mongoose ? The Query.prototype.cast() function casts this query to the schema of the model. And if the obj is present, then it is casted instead of this query.Syntax:  Query.prototype.cast() Parameters: This function has one parameter i.e. the model to cast and if not set, then the default is this.model.Retur 2 min read How does Query.prototype.j() work in Mongoose ? The Query.prototype.j() function is used to request acknowledgement that this operation has been persisted to MongoDB's on-disk journal. Syntax: Query.prototype.j() Parameters: This function has one val parameter of boolean type. Return Value: This function returns Query Object.Installing mongoose 2 min read How does Query.prototype.catch() work in Mongoose ? The Query.prototype.catch() function executes the query and returns a promise which can be resolved with either the doc(s) or rejected with the error.Syntax:  Query.prototype.catch() Parameters: This function has one parameter i.e. a reject callback function.Return Value: This function returns a pr 2 min read How does Query.prototype.box() work in Mongoose ? The Query.prototype.box() is used to specify a $box condition. When this function is used, the $geoWithin returns documents based on the grid coordinates.Syntax:  Query.prototype.box() Parameters: This function has one array object parameter which has upper-left co0rdinates and upper-right coordina 2 min read Like