Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

mongoose
lte
query
communitycreator

What is lte() in Mongoose?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

lte() is a Mongoose function that is used to specify the $lte query condition.

lte means less than or equal to. In the same vein, lte() returns documents that are less than or equal to the specified condition.

Syntax


query.lte()
// OR
Query.prototype.lte()

Parameter

It can take an optional path parameter, and takes a value that is a type of Number.

Code

In the example below, we will create a Schema, make a query, and use the lte() function.

// import mongoose
const mongoose = require("mongoose");
// creating a Schema with mongoose
let Person = mongoose.model("Person", new mongoose.Schema({
name: String,
age: Number
})
)
// make a query and use the `equal()` method
const persons = await Person.find().where("age").lte(70)
/*
OUTPUT : persons is an arrary of objects
that has "age" less than or equal to 70
*/

Explanation

From the code above, persons will be an array of Mongoose documents that have a value in the age field less than or equal to 70.

RELATED TAGS

mongoose
lte
query
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring