In Mongoose, there are many query functions that we use when using Mongoose on our MongoDB database.
Some of the functions include:
lte()
map()
lt()
gt()
ne()
gte()
methodIn this shot, we will look at the gte()
or Query.prototype.gte()
method.
gte()
is used to specify a $gte()
query condition and denotes “greater than or equal to.”
The gte()
method returns documents that match the query condition where the path is greater than or equal to the condition.
We use the where()
method with gte()
when there is only one path.
query.gte(val)
// OR
Query.prototype.gte(val)
gte()
takes a value that is a Number
and can take an optional path parameter that is a String
.
We will demonstrate the use of gte()
by creating a Schema, making a query, and then matching the query with the Schema.
// import mongooseconst mongoose = require("mongoose");// creating a Schema with mongooselet Adult = mongoose.model("adult", new mongoose.Schema({name: String,age: Number}))// make a query and use the `gte()` methodconst adults = await Adult.find().where("age").gte(18)// ORconst adults = await Adult.find().gte("age", 18)/*OUTPUT : adults is an arrary of objectsthat has "age" greater than or equal to 18*/