MongoDB
MongoDB is its own database type in QueryDesk. You query it in a subset of mongosh syntax, and data protection policies redact fields inside MongoDB before any document leaves it. QueryDesk is tested against MongoDB 8.0.
Connect a deployment
Add the database as in Connect a database, with these values:
| Field | Value |
|---|---|
| Database type | MongoDB |
| Port | 27017, MongoDB's default. |
| Database name | The database to query, for example app. |
The MongoDB section of the settings page has the options only MongoDB uses:
- Connect with mongodb+srv:// looks the hostname up as an SRV name, as MongoDB Atlas gives one. Its SRV record lists the servers, and its TXT record can set the authentication database and replica set. An SRV connection always uses TLS.
- Authentication database is the database your users authenticate against, usually
admin. Leave it empty to authenticate against the database name. - Replica set is the set's name. QueryDesk asks the hostname for the set's primary and runs each query there.
- Read the schema from sampled documents is on by default. See Schema.
A mongodb:// or mongodb+srv:// connection string fills these in. Paste it under Update with connection string and click Apply. QueryDesk dials the first host the string lists, maps authSource and replicaSet to their fields, and turns on Encryption for tls=true or an SRV string.
Behind a Tunnel, QueryDesk dials the hostname you give as it is, with no SRV lookup and no search for a primary. Point it at the primary, or at a host that accepts writes if you run any.
Click Test Connection under the credential to check the connection.
Credentials
Give a credential MongoDB's read role on the database if it should only read. MongoDB has no read-only transaction, so for an AI query on a database set to Read only QueryDesk's parser is the only check besides that role. See What Read only enforces.
Write queries
QueryDesk reads mongosh syntax but runs no JavaScript. A statement is a call on a collection, and its arguments are literals, documents, arrays and the shell's type constructors. Variables, functions and loops are refused.
db.orders.find({ status: "paid", total: { $gt: 100 } }).sort({ created_at: -1 }).limit(20)
db.orders.aggregate([
{ $group: { _id: "$customer_id", spent: { $sum: "$total" } } },
{ $sort: { spent: -1 } }
])
db.getCollection("audit-events").countDocuments({ kind: "login" })
These methods are supported:
| Kind | Methods |
|---|---|
| Read | find and findOne (with .sort(), .skip(), .limit() and .projection()), aggregate, countDocuments, estimatedDocumentCount, distinct, getIndexes |
| Write | insertOne, insertMany, updateOne, updateMany, replaceOne, deleteOne, deleteMany, findOneAndUpdate, findOneAndReplace, findOneAndDelete, createIndex, drop |
| Database | db.getCollection("name"), db.getCollectionNames(), db.runCommand({...}) |
db.runCommand takes any command document, so use it for a command with no shell method.
The type constructors are ObjectId, ISODate, Date, NumberInt, NumberLong, NumberDecimal, UUID, Timestamp, BinData, MinKey and MaxKey.
Separate statements with ; or start each on a new line. With the cursor in one statement, Run query runs that statement. Each document is a row of the result, with a column per top-level field. A nested document or array shows as one value. The query's row limit caps the documents read, and with no limit QueryDesk reads at most 10,000.
Analyze and transactions aren't offered on MongoDB. In a workflow, a variable is written into the statement as a string value, since MongoDB has no bound parameters.
Browse and edit collections
The left panel lists the database's collections. Opening one shows its documents, and the filters build a find. Editing a cell runs an updateOne that matches the document's _id and sets the new value with $set. A value you type is read as the shell reads it, so 31 is a number and ObjectId("...") an ObjectId. Text the shell can't read as a value is saved as a string.
The Structure tab lists the collection's fields and indexes.
Schema
Each schema sync samples up to 1,000 documents per collection and stores the fields it finds with their types. QueryDesk stores field paths and types, not values. A nested field is its own path, for example address.city, and so is a field of the documents in an array, for example items.sku. A field name that contains a . or starts with $ is skipped.
Turn off Read the schema from sampled documents to read no documents. A sync then reads each collection's $jsonSchema validator instead, so a collection without one has no fields.
Data protection
A data protection policy lists MongoDB fields as it lists columns, nested paths included. Under a policy, QueryDesk rewrites every read into an aggregate whose first stage is a $project built from the stored schema:
- A shown field is returned as it is.
- A hidden field comes back as
"***", inside its document or array when it is nested. A document that lacks the field still lacks it. - A field the schema doesn't have is left out of the result until a sync stores it.
- A field under Partial, Range, Hash or Placeholder comes back transformed by that stage, read as text with
$toString, so ObjectId and number fields work too. A missing or null field stays as it is.
Hash computes $toHashedIndexKey of the field's text followed by your organization's salt, a 64-bit number, so it needs MongoDB 7.0 or later. On an older server the query fails with MongoDB's own error. The salt is passed in the command's let and never written into the pipeline. A hashed field can't be the join key of a $lookup, since the local side is already hashed when the lookup reads the raw foreign side, so the statement is refused as it is for a hidden field.
Every later stage of your pipeline sees the masked documents, so $group and $project on shown fields work as written. A $match on a shown top-level field still uses its index.
A masked value can't decide which documents come back or what they add up to. QueryDesk refuses a statement that uses a hidden field, or a field computed from one, in a filter, sort, group key, accumulator, distinct, $lookup join or $unwind, and the error names the field:
db.customers.find({ ssn: { $regex: "^123" } })
// Field 'customers.ssn' is redacted, so it can't be used to filter, join or compare documents
A statement QueryDesk can't rewrite safely is refused. That includes server-side JavaScript ($where, $function, $accumulator), $text, $graphLookup, $geoNear, arrayFilters, and any stage or command QueryDesk doesn't model.