MongoDB provides different types of arithmetic expression operators that are used in the aggregation pipeline stages and $floor operator is one of them. This operator is used to find the largest integer less than or equal to the specified number.
Syntax:
{ $floor: <number> }
Here, the number is a valid expression until it resolves to a number.
- If the entered value is null, then this operator will return null.
- If the entered value is NaN, then this operator will return NaN.
- If the entered value is a missing field, then this operator will return null.
Examples:
In the following examples, we are working with:
Database: GeeksforGeeks
Collection: employee
Document: three documents that contain the details of the employees in the form of field-value pairs.

Using $floor operator:
In this example, we are going to find the largest integer less than or equal to the value of the perfoPoint field in the development department.
db.employee.aggregate([{$match: {department: "Development"}},
... {$project: {perfoPoint: 1,
floorPoint: {$floor: "$perfoPoint"}}}])

Using $floor operator in the embedded document:
In this example, we are going to find the largest integer less than or equal to the value of the details.perfoPoint field in the HR department.
db.employee.aggregate([{$match: {department: "HR"}},
... {$project: {"details.perfoPoint": 1,
floorPoint: {$floor: "$details.perfoPoint"}}}])

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
28 Jul, 2020
Like Article
Save Article