11# Ognom shell syntax
22
33The shell tab (and the filter / sort / projection boxes, and the document
4- editor) understand mongosh-flavored syntax — not just strict JSON.
4+ editor) understand mongosh-flavored syntax - not just strict JSON.
55
66Everything below is parsed ** string-aware** : helper syntax inside your string
77data is never rewritten.
@@ -14,7 +14,7 @@ One statement per run. Comments (`//` and `/* */`) are allowed anywhere.
1414db .users .find ({ role: " admin" }, { name: 1 }).sort ({ createdAt: - 1 }).skip (10 ).limit (5 )
1515db .users .findOne ({ _id: ObjectId (" 507f1f77bcf86cd799439011" ) })
1616db .orders .aggregate ([
17- { $match: { status: " paid" } }, // unquoted keys, comments — fine
17+ { $match: { status: " paid" } }, // unquoted keys, comments - fine
1818 { $group: { _id: " $category" , n: { $sum: 1 } } },
1919])
2020db .users .countDocuments ({ active: true })
@@ -23,10 +23,10 @@ db.users.distinct("country", { active: true })
2323
2424db .users .insertOne ({ name: " Ada" , joined: ISODate () })
2525db .users .insertMany ([{ a: 1 }, { a: 2 }])
26- db .users .updateOne ({ _id: ObjectId (" … " ) }, { $set: { active: false } })
26+ db .users .updateOne ({ _id: ObjectId (" ... " ) }, { $set: { active: false } })
2727db .users .updateMany ({ active: false }, { $set: { archived: true } }, { upsert: false })
28- db .users .replaceOne ({ _id: ObjectId (" … " ) }, { name: " Replaced" })
29- db .users .deleteOne ({ _id: ObjectId (" … " ) })
28+ db .users .replaceOne ({ _id: ObjectId (" ... " ) }, { name: " Replaced" })
29+ db .users .deleteOne ({ _id: ObjectId (" ... " ) })
3030db .users .deleteMany ({ archived: true })
3131
3232db .users .getIndexes ()
@@ -59,8 +59,8 @@ capped at **500**.
5959
6060### Updates
6161
62- ` updateOne ` / ` updateMany ` require operator documents (` { $set: … } ` ). For a
63- full replacement use ` replaceOne ` — this mirrors mongosh and prevents
62+ ` updateOne ` / ` updateMany ` require operator documents (` { $set: ... } ` ). For a
63+ full replacement use ` replaceOne ` - this mirrors mongosh and prevents
6464accidental document clobbering.
6565
6666## Value syntax (JSON5 + helpers)
@@ -85,19 +85,27 @@ accidental document clobbering.
8585}
8686```
8787
88- Whole numbers are stored as integers (Int32/Int64), fractional as doubles —
88+ Whole numbers are stored as integers (Int32/Int64), fractional as doubles -
8989the same heuristic mongosh uses. Use ` NumberLong ` / ` NumberDecimal ` / ` Double `
9090to force a type.
9191
9292### Display
9393
9494Results render as relaxed Extended JSON with shell-style affordances:
95- ` ObjectId(… ) ` pills, ISO dates, typed colors in both the JSON tree and the
95+ ` ObjectId(... ) ` pills, ISO dates, typed colors in both the JSON tree and the
9696table. * Copy as shell* produces text that pastes straight back into mongosh
9797or this shell; * Copy as Extended JSON* produces strict JSON.
9898
9999## Not supported (yet)
100100
101101- Multiple statements per run, variables, or arbitrary JavaScript
102- - Regex literals (` /abc/i ` ) — use ` { $regex: "abc", $options: "i" } `
102+ - Regex literals (` /abc/i ` ) - use ` { $regex: "abc", $options: "i" } `
103103- ` findOneAndUpdate ` family, bulk operations, transactions
104+
105+ ## Regular expressions and dates
106+
107+ - ` /pattern/flags ` literals work anywhere a value is expected: ` { topic: /hello/i } ` .
108+ - ` new RegExp("pattern", "flags") ` and ` RegExp("pattern") ` are accepted too, with JavaScript
109+ string escaping (` "\\d+" ` ), and become ` $regularExpression ` .
110+ - ` new Date("2024-01-15") ` , ` Date("...") ` , ` new Date(1700000000000) ` and ` ISODate(...) ` all
111+ produce a BSON date. Any helper may be prefixed with ` new ` .
0 commit comments