Read-only connections and the padlock

Protect production data from accidental writes with the connection's Read-Only Lock and the collection padlock.

Two locks keep you from changing data by mistake:

  • the Read-Only Lock of a connection, saved with it, refuses every write through that connection;
  • the padlock in a collection tab makes one collection read-only for the current session.

Both are checked by the application’s engine before anything is sent to the server, not only by greying out buttons. They are a safety net, not access control: they change neither the user’s roles nor the server. For a truly read-only account, give the database user the read role.

Make a connection read-only

  1. Open the connection dialog (Edit in the Connection Manager).
  2. On the Server tab, tick Read-Only Lock.
  3. Click Save.

The connection shows a lock in the Connection Manager, the connection tree and its tabs. Every write is then refused: document edits, inserts and deletes, imports into it, drops, index changes, user changes, pastes. In IntelliShell, scripts that call a known write method (inserts, updates, deletes, drops, index and collection creation, user and role changes) are refused before they run. That check is best effort: a script can still write through a raw runCommand.

Lock one collection with the padlock

  1. Open the collection.
  2. Click the padlock (Lock) in the result toolbar. Its tooltip reads “Lock: make this collection read-only”.
  3. Every write to the collection is greyed out in Table, Tree and JSON View, and refused if it reaches the engine some other way. Viewing documents still works.
  4. Click the padlock again (Unlock) to allow changes.

The lock lasts for the session: another tab on the same collection opens locked, and the lock is gone after a restart.

Allow changes from one tab of a read-only connection

On a connection with the Read-Only Lock, the padlock shows locked. Clicking it asks Lift Read-Only Lock: “Allow changes to database.collection from this tab?”. Click Allow Changes to let that tab write. Every other tab of the connection stays read-only, and locking the padlock again, closing the tab or ending the session puts the lock back.

Reference

LockScopeSavedLifted by
Read-Only Lockeverything through the connectionwith the connectionclearing it in the connection dialog, or per tab with Allow Changes
Padlockone collectionno (session only)clicking the padlock

Results where _id is excluded by the projection are always read-only: a document cannot be written back without its _id.

Troubleshooting

MessageWhat to do
“The connection is read-only: turn the Read-Only Lock off in the connection’s settings to write.”Intended. Lift it for one tab with the padlock, or edit the connection.
“The collection is locked read-only: click the padlock to allow changes”Click the padlock in the result toolbar.

See also Editing documents.