Help › Write SQL
Query MongoDB
Write MongoDB statements in the shell's syntax or as JSON commands: what Querlyn reads, which methods it runs, and what it refuses.
Querlyn 0.1.0 is not released yet. This help describes it ahead of release.
On a MongoDB connection, the editor takes MongoDB's shell syntax, the way
mongosh and MongoDB's documentation write it:
db.orders.find({ status: "paid", total: { $gte: NumberDecimal("100") } })
.sort({ placed: -1 })
.limit(50)
Querlyn reads each statement and turns it into the command it sends. It does not run JavaScript; see What is not JavaScript. Running, cancelling, the results and the history work as for SQL; see Run statements and scripts.
Write statements
- One statement per line, or several separated by
;. A statement can go on over several lines while its brackets are open, or when the next line starts with., as above. dbis the tab's database.db.ordersis the collectionorders; a name that is not a plain word is writtendb.getCollection("order lines")ordb["order lines"].db.getSiblingDB("sales").ordersnames another database's collection.use saleschanges the tab's database, like the database button above the editor.show dbs,show collections,show usersandshow roleslist what they name.- A JSON command is sent as it is: write the document alone, or
db.runCommand({…}), ordb.adminCommand({…})for theadmindatabase.
{ "listCollections": 1, "nameOnly": true }
Comments are // to the end of the line and /* … */.
⌘/ on macOS or Ctrl+/ on Windows and Linux comments lines with //.
Values
Values are JSON, with what the shell adds:
| Write | Is |
|---|---|
{ name: "Ada" } | Keys without quotes, strings in "…" or '…', a comma after the last item |
42, 3000000000, 1.5 | An integer that fits 32 bits is an int, a larger one a long; a number with a fraction or exponent is a double |
ObjectId("65f1a2b3c4d5e6f708192a3b"), ObjectId() | An ObjectId; with no argument, a new one |
ISODate("2026-10-09T08:30:00Z"), new Date("2026-10-09"), Date() | A date (UTC); Date() with no argument is now |
NumberLong("9007199254740993"), NumberInt(7), Double(1) | A long, an int, a double |
NumberDecimal("100.50"), Decimal128("100.50") | A decimal, kept exactly |
UUID("…"), BinData(0, "…"), HexData(0, "…") | Binary values |
Timestamp(1700000000, 1), MinKey(), MaxKey() | As in the shell |
/^ada/i, RegExp("^ada", "i") | A regular expression |
{ "$oid": "…" }, { "$date": "…" }, { "$numberDecimal": "…" } | Extended JSON, read as the type it names |
Note: mongosh stores an integer too large for 32 bits as a double;
Querlyn stores it as a long, so it stays exact. Write Double(…) for a
double.
What runs
| On | Methods |
|---|---|
| A collection | find, findOne, aggregate, countDocuments, estimatedDocumentCount, count, distinct, insertOne, insertMany, insert, updateOne, updateMany, replaceOne, update, deleteOne, deleteMany, remove, findOneAndUpdate, findOneAndReplace, findOneAndDelete, createIndex, createIndexes, ensureIndex, dropIndex, dropIndexes, getIndexes, drop, renameCollection, stats, dataSize, storageSize, totalIndexSize, totalSize, isCapped, validate, explain |
After find | sort, limit, skip, projection, project, hint, collation, comment, maxTimeMS, batchSize, min, max, returnKey, showRecordId, allowDiskUse, readConcern, noCursorTimeout, count, explain, pretty, toArray |
db | runCommand, adminCommand, getCollection, getSiblingDB, getCollectionNames, getCollectionInfos, createCollection, createView, dropDatabase, stats, serverStatus, version, serverBuildInfo, hello, isMaster, hostInfo, listCommands, getUsers, getRoles, currentOp, killOp, aggregate |
rs | status, conf, config, hello, isMaster |
Anything else is refused before it is sent, with the reason under the statement, as is a method given the wrong arguments.
A read streams its documents: the first batch shows at once and more are
fetched as you scroll, as for SQL. Without .limit(…) a find reads
on demand to the end of the collection.
Completion
Completion offers what fits where the cursor is: collections after db.,
methods after a collection or a cursor, the fields of the collection
(from a sample of its documents) in a filter, a projection, a sort or an
update, $ operators, and aggregation stages in a pipeline. See
Complete SQL as you type.
Safety
Querlyn judges each statement by the command it plans to send, so
db.orders.deleteMany({}) and { "delete": "orders", "deletes": [ … ] }
are judged alike.
- On Testing, Staging and Production, it asks first for statements
that destroy data:
dropDatabase(),drop(), a delete or an update whose filter matches every document ({},{ _id: { $exists: true } }), dropping indexes, an aggregation that ends in$out,renameCollectionwithdropTarget,convertToCapped, dropping users or roles, revoking roles or privileges, and commands that stop or reconfigure the server. - Granting roles or privileges is not checked for what it gives away: Production asks about it.
- A command Querlyn does not know is treated as one that changes data: Production asks, a read-only connection refuses it.
- A read-only connection refuses every write,
$outand$mergeincluded.
See Confirm risky statements and Read-only connections.
What is not JavaScript
Querlyn reads statements, it never runs them as a program. So these are refused, with a sentence saying so:
- variables (
let,const,var) and names that are not values; - functions and arrow functions.
$whereandCode(…)take their code as a string, which the server runs; - loops,
if, arithmetic and string operations (1 + 1,"a" + b); load(),print(),printjson()and the shell's helpers outside the tables above.
To compute a value on the server, use the aggregation pipeline's
operators ($add, $concat, $dateAdd), which Querlyn sends as they
are. For a real script, turn on script mode: the tab then runs as one
script in your installed mongosh, outside Querlyn's checks; see
Run a MongoDB script in mongosh.
Help for Querlyn 0.1.0. All help topics