Help › Connect to databases

Connect to MongoDB

Connect to MongoDB or MongoDB Atlas with a password, an X.509 certificate, AWS IAM or OIDC, read documents in the results, and what is particular to MongoDB.

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

Querlyn talks to MongoDB with MongoDB's own protocol, through the same routes as any other database: directly, through SSH, Kubernetes or AWS Systems Manager. Each MongoDB database is listed in the sidebar with its collections and views. Queries are written in the MongoDB shell's syntax, such as db.orders.find({ status: "paid" }); see Query MongoDB.

What you need

  • MongoDB 4.0 or later: a single server, a replica set, a sharded cluster's mongos, or MongoDB Atlas.
  • The server's host name, or for Atlas the cluster's name from its mongodb+srv:// connection string.
  • A user and password, a client certificate for X.509, AWS credentials for AWS IAM, or an Atlas organization's identity provider for OIDC. A server without access control needs none.

Fill in the dialog

  1. Choose File › New Connection… and, under Database engine, MongoDB. Or copy the connection string and use Command Palette › Database: Paste Connection URL: it fills in everything below except the password.

  2. Under Connect with, choose:

    Connect withWhat it means
    Host and portHost and Port (27017) name one server. Other hosts names more members of the replica set, tried when the first does not answer.
    DNS seed list (mongodb+srv)The mongodb+srv:// form Atlas gives. Host holds the cluster's name, such as cluster0.ab1cd.mongodb.net; DNS names the servers, the replica set and the authentication database. The port is not used.
  3. Database is the database query tabs start in. Empty means test, as in the MongoDB shell.

  4. Under Authentication, Password signs in with MongoDB's own users; AWS IAM and OIDC (workforce) sign in with your cloud identity, as Sign in with AWS, Entra ID, Google Cloud or OIDC explains, and need TLS. With Password, under Sign in with, choose:

    Sign in withWhat it does
    PasswordSCRAM-SHA-256 where the user has it, SCRAM-SHA-1 otherwise, as the server says.
    Password (SCRAM-SHA-256), Password (SCRAM-SHA-1)Only that mechanism.
    X.509 certificateThe client certificate signs you in. Under Client certificate, choose a PEM file holding the certificate and its private key, not encrypted. Querlyn reads it at each connect and keeps only its path. User may stay empty: the certificate's subject is the user.
    NoneNo sign-in, for a server without access control. A Password sign-in with User left empty does the same.
  5. With a password, Authentication database is the database the user is defined in. Empty means the database of step 3, or admin when none is set; Atlas users are defined in admin.

  6. Choose where the password is kept; see Choose where passwords are kept.

  7. Optionally:

    • Replica set: the replica set's name. Empty lets the server say.
    • Members (with Host and port): Find the primary goes to the replica set's primary from any member. This server only stays on the host you named even when it is a secondary, so writes fail there. Through a Kubernetes or AWS Systems Manager route, only This server only works, because the route reaches one server.
    • Read from: which member query tabs read from: Primary, Primary preferred, Secondary, Secondary preferred or Nearest. Writes always go to the primary.
  8. Choose Test Connection, then Save & Connect.

TLS works as for other databases; see Encrypt a connection. A pasted mongodb+srv:// connection string sets Verify full, as MongoDB's own tools turn TLS on for it.

Read documents in the results

  • Columns come from the first batch. The first batch of documents (500) decides the columns: _id first, then each field in the order it was first seen. When more documents follow, a last column, Other fields, holds the fields of later documents that are not columns, so nothing is hidden.
  • A field a document does not have is empty, which is not the same as null: a null field shows as NULL.
  • Embedded documents and arrays show as JSON in one cell, in MongoDB's relaxed Extended JSON, which keeps BSON's types: {"$oid": "65f1…"}, {"$numberDecimal": "100.50"}. Value above the grid shows a long one in full.
  • Flatten above the grid (View › Flatten Embedded Documents, also View › Flatten Embedded Documents) shows each embedded document's fields as columns of their own, named by their path: address.city, address.geo.lat. It goes three names deep and up to 500 columns; a deeper document, or one whose fields would pass 500 columns, stays one JSON cell, and the message Flatten shows says so. Arrays stay one JSON cell. A field that also holds something else in some documents (a string, null, an empty document) keeps a column of its own name for that. Flatten is off for each new result and changes only what you see: copying and exporting the loaded rows take the columns shown, exporting all rows (which runs the query again) waits until Flatten is off, and turning it off shows the documents as they came.
  • Record above the grid shows the current document whole, as a tree: each embedded document and array folds and unfolds by its arrow. See Look at one row or one value.
  • Exporting to JSON writes each document with the fields it has; to CSV, a missing field is an empty cell. See Export results.
  • Writes say what they did under Messages: insertMany: 3 inserted, updateMany: 12 matched, 12 modified.

What is particular to MongoDB

  • The sidebar lists the databases your user may see, and in each its collections (with the server's estimate of their documents) and views. A time series collection says so. Expanding a collection shows the fields of a sample of 100 documents, with their types, and its indexes. Opening a collection's data runs db.getCollection("name").find({}) in a new query tab.
  • A tab's database is chosen with the database button above the editor, or with use name in the editor. db in a statement is that database.
  • Transactions need a replica set or a sharded cluster. There, a tab that commits by hand holds its writes until Commit or Roll Back, as on any database; a Production connection starts that way. On a single server, every statement commits by itself. A transaction has a time limit on the server, 60 seconds by default, after which MongoDB rolls it back: while one is open, the bar above the editor counts down, Commit within 40 s. See Commit and roll back changes.
  • Documents can be edited in the results: fields changed or removed, a whole document as JSON, documents added and deleted, each by its _id, with every value keeping its type. See Edit MongoDB documents.
  • Cancel stops a running statement on the server (killOp).
  • Server Activity lists the server's operations and idle sessions. Cancel Query stops an operation (killOp); Terminate Session… ends its session (killSessions). Without the inprog privilege the list has only your own operations. See See what runs on the server.
  • Explain shows the plan MongoDB chooses for a find, an aggregate, a count, distinct or a write, without running it; a collection scan is pointed out. Explain Analyze runs it to measure each stage (documents returned, documents and index keys examined, time) and marks the heaviest; a write is evaluated, not applied. See See a query's execution plan.
  • Confirmations are in MongoDB's words: dropping a database or a collection, or deleting or updating every document, asks first on Testing, Staging and Production; a command Querlyn cannot judge asks on Production. See Query MongoDB and Confirm risky statements.
  • Read-only is Querlyn's check. It refuses writes and commands that change anything before they are sent. A user with only read roles is the stronger guard.
  • Show Definition on a view shows the db.createView(…) that makes it.
  • Completion offers collections, the fields of the collection a statement is about (from the same sample), shell methods, query and update operators, and aggregation stages.

What Querlyn does not do

  • Run JavaScript in its own sessions. Statements are read, never run as a program: no variables, loops or functions. For a script, turn on script mode, which runs the tab in your installed mongosh; see Run a MongoDB script in mongosh.
  • Sign in with LDAP, Kerberos or OIDC for machines (Atlas's workload identity). A connection string that asks for one is imported with a user and password instead, and says so. A string that asks for AWS IAM or OIDC is imported with that sign-in, without any AWS keys it holds.
  • Dry Run, the table designer, ER diagrams, schema compare, Compare Data, copying tables, importing files, profiling a whole collection, running on several connections, query parameters, formatting and refactoring: they are written for SQL. Each says so when you choose it.
  • Users and roles: run db.getUsers() and db.getRoles(), or manage them in MongoDB's own tools.
  • Backup and restore: use mongodump and mongorestore.
  • Lock and statement timeouts, the "blocking others" notice and migration lock warnings.

Help for Querlyn 0.1.0. All help topics