Help › Work with results

Edit MongoDB documents

Change and remove fields in the results, edit a whole document as JSON, add and delete documents, and how each value keeps its type.

Querlyn 0.1.0 is not released yet. This help describes it ahead of release.

On a MongoDB connection you can change documents straight in the results, as you change rows on other databases; see Edit rows in a result. Nothing reaches the server while you edit: your changes are collected, Show Changes shows the statements they become, and Apply sends them. Each change is one statement for one document, found by its _id.

When documents can be edited

The line above the grid says Editable and the collection, or Read-only and why. Documents can be edited when all of this holds:

  • They come from a find on one collection, such as db.orders.find({ status: "open" }), with any filter, sort and limit. The documents of an aggregate, of a view or of a command are read-only: edit them with a find on their collection.
  • The result includes _id. A projection that leaves _id out makes the result read-only.
  • The connection is not read-only.

Within an editable result:

  • _id cannot change. It is what finds the document. To give a document another _id, insert a copy and delete the original.
  • A document without _id, or whose _id another document of the result has too, cannot be changed from the grid; the row says why.
  • A field the projection computes, such as { total: { $sum: … } }, is not a field to write.

Change a field

Edit a cell as on any database (Query › Edit Cell, ↩ on macOS or F2 on Windows and Linux, or a double-click). The change becomes updateOne({ _id: … }, { $set: { field: value } }).

Every value keeps its type. What you type is read as the type the cell already has, so editing never changes a field's type by accident:

The field isYou typeIt stays
an int42an int; a number too large for 32 bits is refused
a long42a long, also when it is small
a double1.5a double
a decimal100.50a decimal, exactly as typed
a string42the string "42"
an ObjectId24 hexadecimal digitsan ObjectId
a date2026-10-09T08:30:00Za date

To change a field's type, write the value in the shell's syntax: NumberLong("5"), NumberInt(5), Double(5), NumberDecimal("5"), ObjectId("…"), ISODate("…"), or a string in quotes, "5". Querlyn never turns a 64-bit integer into a double, so large numbers stay exact.

An embedded document or an array is typed as JSON in its cell, or edited in the larger editor (Command Palette › Results: Edit Cell in Larger Editor). With Flatten on, a column such as address.city edits that field of the embedded document; see Connect to MongoDB.

Remove a field

A field a document does not have is different from a field that holds null, and the grid keeps them apart: a missing field is an empty cell, null is NULL.

  • NULL (Command Palette › Results: Set to NULL) stores null in the field.
  • Missing removes the field from the document ($unset). Choose Missing in the bar above the grid while you edit a cell, or select cells and choose Command Palette › Results: Remove Field (Set Missing) in the grid's menu.

Edit a whole document as JSON

To change many fields at once, or a document whose fields the columns do not show (the Other fields column), edit it whole:

  1. Put the cursor on the document and choose JSON in the bar above the grid, Edit as JSON in the record view, or Command Palette › Results: Edit Document as JSON…. Querlyn reads the document from the server first, so you edit it as it is now, with every value's exact type.
  2. Edit it in the larger editor. It is shown as relaxed Extended JSON, with each 64-bit integer written { "$numberLong": "…" } so it stays a long. Show Canonical shows every value's type in full; Show Relaxed goes back.
  3. What you type is checked as you go: it must read as one document and keep its _id. The reason shows under the editor until it does.
  4. Choose Keep. The document is replaced as a whole when you apply (replaceOne({ _id: … }, …)).

Add and delete documents

  • Add in the bar above the grid (Query › Add Row) adds an empty document; Command Palette › Results: Duplicate Rows adds copies of the selected ones without their _id. Fill in the fields you want: an empty cell is left out of the document. Without an _id, the server gives the document one. Each becomes insertOne(…).
  • Delete (Query › Delete Rows) marks the selected documents; each becomes deleteOne({ _id: … }).

Review and apply

Changed cells, new documents and deleted ones are marked in the grid until you apply or revert them.

  • Show Changes (Query › Preview SQL for Pending Changes) shows the statements, in the shell's syntax, for example db.getSiblingDB("shop").getCollection("orders").updateOne({ _id: ObjectId("…") }, { $set: { status: "paid" } }).
  • Apply (⌘S on macOS or Ctrl+S on Windows and Linux) sends them in order. On Production Querlyn asks first; a read-only connection refuses. See Confirm risky statements.
  • Query › Revert All Pending Changes drops them.

If a change matches no document, it was deleted or its _id changed since the query ran: Querlyn says so, keeps the change pending, and you can run the query again to see the documents as they are now.

Each statement is listed in the statement console with its values by reference, never in the text; see Watch what Querlyn sends.

Changes and transactions

On a replica set or a sharded cluster, a tab that commits by hand (a Production connection starts that way) applies the changes inside its transaction: they are kept only when you commit. MongoDB rolls back a transaction left open longer than its limit, 60 seconds by default, so the bar above the editor counts down, Commit within 40 s, until you commit; choosing it commits. See Commit and roll back changes.

On a single server, each change takes effect when it is applied.

Help for Querlyn 0.1.0. All help topics