Finding documents in MongoDB collection where a field is equal to given integer value?

To find documents where a field is equal to a given integer value, use the find() method with the field name and integer value in the query condition.

Syntax

db.collection.find({"fieldName": integerValue});

Sample Data

Let us create a collection with documents −

db.demo472.insertMany([
    {"Project_Id": -101, "ProjectName": "Online Customer Tracking"},
    {"Project_Id": 101, "ProjectName": "Online Banking System"},
    {"Project_Id": 102, "ProjectName": "Online Library System"}
]);
{
    "acknowledged": true,
    "insertedIds": [
        ObjectId("5e80586cb0f3fa88e227907a"),
        ObjectId("5e805884b0f3fa88e227907b"),
        ObjectId("5e805893b0f3fa88e227907c")
    ]
}

Display all documents from the collection −

db.demo472.find();
{ "_id": ObjectId("5e80586cb0f3fa88e227907a"), "Project_Id": -101, "ProjectName": "Online Customer Tracking" }
{ "_id": ObjectId("5e805884b0f3fa88e227907b"), "Project_Id": 101, "ProjectName": "Online Banking System" }
{ "_id": ObjectId("5e805893b0f3fa88e227907c"), "Project_Id": 102, "ProjectName": "Online Library System" }

Example

Find documents where Project_Id equals -101

db.demo472.find({"Project_Id": -101});
{ "_id": ObjectId("5e80586cb0f3fa88e227907a"), "Project_Id": -101, "ProjectName": "Online Customer Tracking" }

Conclusion

Use find() with the field name and exact integer value to match documents. MongoDB performs precise equality matching for integer fields without type conversion.

Updated on: 2026-03-15T03:05:46+05:30

302 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements