Query Operators
PlugPort supports a subset of MongoDB query operators. All operators work identically across the HTTP API, wire protocol, and SDKs.
Comparison Operators
$eq - Equals
{ "status": { "$eq": "active" } }
// Shorthand (implicit $eq):
{ "status": "active" }
$ne - Not Equals
{ "status": { "$ne": "inactive" } }
$gt - Greater Than
{ "age": { "$gt": 25 } }
$gte - Greater Than or Equal
{ "age": { "$gte": 18 } }
$lt - Less Than
{ "price": { "$lt": 100 } }
$lte - Less Than or Equal
{ "score": { "$lte": 50 } }
$in - In Array
{ "role": { "$in": ["admin", "moderator", "editor"] } }
Combining Range Operators
{ "age": { "$gte": 18, "$lt": 65 } }
Logical Operators
$and - Logical AND
{
"$and": [
{ "status": "active" },
{ "age": { "$gte": 18 } }
]
}
Implicit AND
Multiple conditions in the same filter document use implicit AND:
{ "status": "active", "age": { "$gte": 18 } }
This is equivalent to the explicit $and above.
Index Usage
Operators that can use index scans for better performance:
| Operator | Index Scan? | Notes |
|---|---|---|
$eq | ✅ Yes | Exact key lookup |
$gt | ✅ Yes | Range scan from value |
$gte | ✅ Yes | Range scan from value (inclusive) |
$lt | ✅ Yes | Range scan up to value |
$lte | ✅ Yes | Range scan up to value (inclusive) |
$ne | ❌ No | Full scan with post-filter |
$in | ❌ No | Multiple lookups, falls back to scan |
$and | ⚠️ Partial | Uses best single-field index |
Create indexes on fields you query with $eq, $gt, $gte, $lt, $lte for optimal performance.
Projection
Control which fields are returned:
Include Fields
{ "projection": { "name": 1, "email": 1 } }
Returns only _id, name, and email.
Exclude Fields
{ "projection": { "password": 0, "internalNotes": 0 } }
Returns all fields except password and internalNotes.
Do not mix include (1) and exclude (0) in the same projection (except _id). This matches MongoDB's behavior.
Sort
{ "sort": { "age": 1 } } // Ascending
{ "sort": { "age": -1 } } // Descending
{ "sort": { "age": -1, "name": 1 } } // Multi-field sort
Pagination
{
"filter": {},
"sort": { "createdAt": -1 },
"skip": 20,
"limit": 10
}
Update Operators
$set - Set Fields
{
"update": {
"$set": {
"name": "Updated Name",
"metadata.lastModified": "2024-01-01T00:00:00Z"
}
}
}
$inc - Increment Fields
{
"update": {
"$inc": { "views": 1, "score": -5 }
}
}
Increments numeric fields by the specified amount. Use negative values to decrement.
$unset - Remove Fields
{
"update": {
"$unset": { "temporaryField": "" }
}
}
Removes the specified fields from the document.
Additional Query Operators
$or - Logical OR
{ "$or": [{ "status": "active" }, { "role": "admin" }] }
Matches documents that satisfy at least one of the expressions.
$nin - Not In Array
{ "status": { "$nin": ["deleted", "archived"] } }
Matches documents where the field value is not in the specified array. Inverse of $in.
$exists - Field Exists
{ "email": { "$exists": true } }
Matches documents that have (or don't have) the specified field.
Roadmap Operators
These operators are planned for future releases:
| Operator | Type | Status |
|---|---|---|
$not | Logical | Planned |
$regex | Evaluation | Planned |
$type | Element | Planned |
$push | Array Update | Planned |
$pull | Array Update | Planned |