Use Extended JSON in MongoDB filters
Plain JSON cannot express MongoDB types such as ObjectId, dates or 64-bit integers, so DevOpsPad reads filter, projection and sort as MongoDB Extended JSON. Write {"$oid": "…"} for an ObjectId and {"$date": "…"} for a date, and the filter matches the stored BSON type.
Both relaxed and canonical Extended JSON are accepted as input. Results always come back as canonical Extended JSON, which keeps every type visible and every number exact.
Common filters
Match a document by ObjectId:
{
"collection": "orders",
"filter": { "_id": { "$oid": "507f1f77bcf86cd799439011" } }
}
Documents created since a point in time:
{
"collection": "orders",
"filter": { "createdAt": { "$gte": { "$date": "2026-11-01T00:00:00Z" } } },
"sort": { "createdAt": -1 }
}
An exact 64-bit integer or a decimal:
{
"collection": "ledger",
"filter": {
"accountId": { "$numberLong": "9007199254740993" },
"amount": { "$gt": { "$numberDecimal": "100.00" } }
}
}
| Type | Extended JSON |
|---|---|
| ObjectId | {"$oid": "507f1f77bcf86cd799439011"} |
| Date | {"$date": "2026-11-01T00:00:00Z"} |
| 64-bit integer | {"$numberLong": "9007199254740993"} |
| Decimal128 | {"$numberDecimal": "100.00"} |
| Regular expression | {"$regularExpression": {"pattern": "^ord", "options": "i"}} |
Query operators such as $in, $exists and $regex work as usual, because they are part of the filter document.
Why a plain string does not match
{"_id": "507f1f77bcf86cd799439011"} looks for a string _id. If the stored value is an ObjectId, nothing matches. The same applies to dates stored as BSON dates and compared with ISO strings. Wrap the value in the right Extended JSON type.
Reading results
Results use canonical Extended JSON. You will see values like:
{
"_id": { "$oid": "507f1f77bcf86cd799439011" },
"createdAt": { "$date": { "$numberLong": "1762387200000" } },
"quantity": { "$numberInt": "3" },
"accountId": { "$numberLong": "9007199254740993" }
}
That format is more verbose than the shell, but nothing is rounded. A JavaScript number cannot hold 9007199254740993 exactly; as $numberLong text it survives the trip to the result grid and to CSV export.
Errors
filter must be a JSON object: the value is an array or a string. Wrap it in{ }.Invalid filter: …: the Extended JSON is malformed, for example an$oidthat is not 24 hex characters.
Frequently asked questions
How do I filter by _id in DevOpsPad?
Wrap the hex string in $oid, for example {"_id": {"$oid": "507f1f77bcf86cd799439011"}}. A plain string does not match an ObjectId.