Node.js MongoDB Query
Here is a clean, simple, and complete guide for Node.js MongoDB Query — also known as MongoDB Find with Conditions.
✅ Node.js MongoDB Query (Find With Conditions)
To “query” in MongoDB means using find() or findOne() with filters.
MongoDB filters allow you to select documents using:
Field matching
Comparison operators
Logical operators
Pattern matching (regex)
Array queries
Nested document queries
Below are all important query examples using Node.js.
⭐ 1. Basic Query (LIKE WHERE)
Find documents where name = "John"
Find all matching
⭐ 2. Query With Multiple Conditions (AND)
Equivalent to SQL: WHERE name='John' AND address='Highway 37'
⭐ 3. OR Query
SQL Equivalent: WHERE name='John' OR name='Peter'
⭐ 4. Comparison Operators
| Operator | Meaning |
|---|---|
$gt | Greater than |
$lt | Less than |
$gte | Greater or equal |
$lte | Less or equal |
$ne | Not equal |
$in | Match any in array |
$nin | Not in array |
Example: age > 25
Example: Age between 20 and 30
⭐ 5. Query Using Regular Expression (LIKE in SQL)
Find names starting with “J”
Contains “hn”
⭐ 6. Query Nested Documents
If your document is like:
