Skip to content

MongoDB

DataKlin connects to MongoDB 7.0 and later through its built-in MongoDB connector: a standalone server, a replica set, or a mongodb+srv:// cluster. It signs in with a user and password, a client certificate (X.509) or no authentication, and encrypts the connection with TLS: a new connection to a remote server uses Full verification, which checks that the server’s certificate comes from a trusted authority and names the server.

Supported versions MongoDB 7.0 and later

  • TLS
  • Connection string
  • Replica sets
  • Schema view
  • Completion
  1. Open New Connection. Click New Connection in the header of the Database Explorer, choose File › New Connection…, or press Ctrl+K, then Ctrl+N (Cmd+K, then Cmd+N on macOS). Getting started lists every way to open it.

  2. Choose MongoDB. Type mongo in Search connectors… and press Enter, or double-click MongoDB.

  3. Choose Connection string or Fields. In the Server section, the Connection string | Fields switch picks how you describe the server. Paste a mongodb:// or mongodb+srv:// string, or fill in Hosts, Port and the rest. Use one of the two, not both. See Connection fields.

  4. Check Security. Open Security to choose the Authentication method and the TLS mode. A remote host starts at Full verification; localhost isn’t encrypted. Type the User and Password in the Authentication fields. See Authentication and TLS.

  5. Test the connection. Click Test connection. When it works, the server version shows beside the button. When it doesn’t, the reason shows, with Copy details. Once the connection is saved, Show Connection Log shows the full log.

  6. Save. Click Save, or Save and connect to connect at once. The connection appears in the Database Explorer.

The New connection dialog for MongoDB in DataKlin, with the connection's name, folder and server fields filled in

The Connection section at the top (Name, Folder, Environment and a color) is the same for every database: see Getting started. The Server section has a Connection string | Fields switch, and each choice shows its own fields. Options is the collapsed section at the bottom of the dialog.

One field holds the whole address, with the user and any options the connector reads in the string.

FieldWhat it doesDefaultExample
Connection stringA mongodb:// or mongodb+srv:// URL. Its password belongs in Password, which is kept in the vault. At most 2,048 characters.Nonemongodb+srv://app@cluster0.example.net/shop

A connection uses a string or the fields. A string together with Hosts, Replica set or Database is refused.

FieldWhat it doesDefaultExample
UserUser and passwordThe database user to sign in as. At most 1,024 characters.Noneapp
PasswordUser and passwordStored in the DataKlin vault, never in the connection file. Next to it, Keep password chooses how long DataKlin keeps it: Save, Until DataKlin quits or Ask every time.None—
MechanismUser and passwordAuto lets the server choose (SCRAM-SHA-256 where the user has it).autoauto
Auth databaseUser and passwordThe database the user is defined in. At most 64 characters.adminadmin
FieldWhat it doesDefaultExample
App nameShown to the server as the connection's appName, for example in $currentOp. At most 128 characters.DataKlinDataKlin
Connect timeout (seconds)How long to wait for a server, also to select one of a replica set. From 1 to 3600.1010
Schema sample sizeHow many documents the Schema view samples with $sample. From 100 to 10000.10001000
FieldWhat it doesDefaultExample
Read-onlyMark this connection as one that should not change data. DataKlin then refuses writes and schema changes before they reach the database. Choosing a protected environment, such as Production, ticks it for you.OffOn
Disconnect when idleClose this connection after it has sat unused. Reconnects on your next action. Choose Use default, Never, or After… and a number of minutes.Use defaultNever

Paste a mongodb:// or mongodb+srv:// string into the Connection string field. A mongodb+srv:// string looks the cluster’s hosts up in DNS and uses TLS.

mongodb://app@db-1.internal:27017,db-2.internal:27017/shop?replicaSet=rs0
mongodb+srv://app@cluster0.example.net/shop
  • Put the password in Password, not in the string. A password you paste in a string moves to the Password field and is kept as Secret storage describes. A saved connection string that holds a password is refused. The string is at most 2,048 characters.
  • The options replicaSet, directConnection, readPreference, authSource, authMechanism and appName fill the matching fields when you switch to the Fields view. DataKlin accepts other driver options too, such as tls, retryWrites, w and maxPoolSize. It refuses by name the other tls* and ssl* settings such as tlsCAFile, timeoutMS, proxy*, authMechanismProperties and any option it doesn’t know. Choose the CA and client certificates in the Security section instead.
  • Write an IPv6 host in brackets, such as mongodb://app@[::1]:27017/shop.

Open Security to choose how DataKlin signs in. The Authentication method is one of:

  • User and password (the default): the User and Password fields. Mechanism is auto, SCRAM-SHA-256 or SCRAM-SHA-1, and the Auth database is admin unless you set it.
  • No authentication: for a server that doesn’t ask for a user.
  • Client certificate (X.509): the server identifies you by the certificate you choose under TLS.

The TLS mode is one of Disable, Require, Verify CA and Full verification; there is no Prefer mode. A new connection to a remote host uses Full verification, and so does a mongodb+srv:// string; one to localhost, 127.0.0.1 or ::1 isn’t encrypted. A plain server on another host needs Disable. With TLS on you can also choose a CA certificate, a Client certificate, the Server name and the Minimum TLS version. TLS and certificates explains each mode and certificate.

No server to hand? Start MongoDB in Docker:

Terminal window
docker run --name dataklin-mongo -d -p 27017:27017 mongo:8.0

Then connect with these values, on the Fields tab:

Field Value
Hosts localhost
Port 27017
Authentication method No authentication
TLS mode Disable, the default for localhost

When you’re done, remove the container with docker rm -f dataklin-mongo.

  • The console is a safe subset of the mongo shell. It reads what you type and never runs it as JavaScript, so it refuses functions and arrows, forEach, variables and loops, $where, $function and $accumulator. Map and Code values are refused, and so are the commands mapReduce, eval and group, which run JavaScript on the server. A refusal names the place it found and sends nothing to the server. Copy the statement to mongosh for anything else.
  • Deleting statements ask first. deleteOne and deleteMany, drop, dropDatabase, an aggregation with $out or $merge, and an update with an empty filter ask for confirmation before they run, and a protected environment such as Production asks for the connection’s name. See Confirming destructive statements.
  • Read-only refuses writes. On a read-only connection, DataKlin refuses writes before they reach the server. See Read-only connections.
  • Schema sample size. The Schema view samples that many documents with $sample to show a collection’s fields. A higher number gives a fuller picture of a collection whose documents differ, and takes longer to read.
  • A read-only user is enough. The read role on the database you browse covers the Database Explorer, browsing, Schema and Indexes.
  • Completion. The console and the browse bar’s Filter, Project and Sort complete method, operator and stage names without a connection. Database, collection and field names come from the connection, read only; field names come from the Schema sample and never include a document’s values. $where and the other server JavaScript names are never offered.
  • SSH tunnels. A tunnelled connection needs Direct connection on, so it reaches one host; a mongodb+srv:// string can’t be tunnelled.