How does Query.prototype.hint() work in Mongoose ? Last Updated : 17 Mar, 2021 Comments Improve Suggest changes Like Article Like Report The Query.prototype.hint() function is used to set the query hints. A hint object is passed as parameter to this function. Syntax: Query.prototype.hint() Parameters: This function has one parameter val which is an hint object.Return Value: This function returns Query Object. Mongoose Installation: npm install mongoose After installing the mongoose module, you can check your mongoose version in command prompt using the command. npm mongoose --version 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 } }); var query = User.find(); query.hint({index:1}) console.log("Hint:", query.options) The project structure will look like this: Run index.js file using below command: node index.js Output: Hint: { hint: { index: 1 } } 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 } }); var query = User.find(); query.hint({index: -1}) console.log("Hint:", query.options) app.listen(3000, function(error ) { if(error) console.log(error) console.log("Server listening on PORT 3000") }); Run index.js file using below command: node index.js Output: Server listening on PORT 3000 Hint: { hint: { index: -1 } } Reference: https://mongoosejs.com/docs/api/query.html#query_Query-hint Comment More infoAdvertise with us Next Article How does Query.prototype.hint() work in Mongoose ? G gouravhammad Follow Improve Article Tags : Web Technologies Node.js Node.js-Methods Mongoose NodeJS-Questions +1 More Similar Reads How does Query.prototype.gt() work in Mongoose? The Query.prototype.gt() function is used to specify a $gt query condition. It returns documents that are greater than the specified condition. Syntax:  Query.prototype.gt() Parameters: This function has one val parameter and an optional path parameter.Return Value: This function returns Query Obje 2 min read How does Query.prototype.gte() work in Mongoose ? The Query.prototype.gte() function is used to specify a $gte query condition. It returns documents that are greater than or equal the specified condition. Syntax:  Query.prototype.gte() Parameters: This function has one parameter val and an optional parameter path.Return Value: This function retur 2 min read How does Query.prototype.get() work in Mongoose? The Query.prototype.get() function is used for the update operations, and it returns the value of a path in the update's $set. Syntax:  Query.prototype.get() Parameters: This function has two parameters, one is path parameter and other is optional val parameter to set the value.Return Value: This f 2 min read How does Query.prototype.explain() work in Mongoose? The Query.prototype.explain() function is used to set the explain option thereby making this query return detailed execution stats instead of the actual query result. Syntax: Query.prototype.explain() Parameters: This function has one optional verbose parameter.Return Value: This function returns Qu 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 Like