Skip to main content

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:

OperatorIndex Scan?Notes
$eq✅ YesExact key lookup
$gt✅ YesRange scan from value
$gte✅ YesRange scan from value (inclusive)
$lt✅ YesRange scan up to value
$lte✅ YesRange scan up to value (inclusive)
$ne❌ NoFull scan with post-filter
$in❌ NoMultiple lookups, falls back to scan
$and⚠️ PartialUses best single-field index
tip

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.

warning

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:

OperatorTypeStatus
$notLogicalPlanned
$regexEvaluationPlanned
$typeElementPlanned
$pushArray UpdatePlanned
$pullArray UpdatePlanned