Mongoose Query.prototype.gte() API
Mongoose is an Object Data Modeling (ODM) library for MongoDB. It defines a strongly-typed schema, with default values and schema validations which are later mapped to a MongoDB document.
This method is used to select those documents where the value of the field is greater than or equal to(>=) the given value.
- path: It is a string that represents the field name, this is a must-have parameter.
- val: It is the number, greater than which we want to find the documents of that path.
Installation of mongoose module:
Step 1: You can visit the link to Install the mongoose module. You can install this package by using this command.
npm install mongoose
Step 2: After installing the mongoose module, you can check your mongoose version in the command prompt using the command.
npm version mongoose
Step 3: After that, you can just create a folder and add a file for example index.js, To run this file you need to run the following command.
Project Structure: The project structure will look like this:
Example 1: We have some data of customers that contains their names, interests, and orderCount. In this example, we want to find customers whose order counts are greater than or equal to 6.
Steps to run the application:
Step 1: Below is the sample data in the database before the function is executed, You can use any GUI tool or terminal to see the database like we have used the MongoDB compass GUI tool as shown below:
Step 2: Run the index.js file using the below command:
Example 2: In this example, we are passing nothing as a value in this method. We see that it returns all the documents of that field.
Step to run the application: Run the index.js file using the below command:
Please Login to comment...