How to Connect to MongoDb

Read first the Connection dialog page to understand the dialog fields( host, port, user, etc. ), SSH tunnel, etc. For a detailed list of MongoDb features read this page.

DbSchema can connect to MongoDb using the native MongoDb Java URI. In the connection dialog advanced tab you can enable custom URI and enter the same URI you would use from any Java application to connect. DbSchema created a JDBC driver for MongoDb on top of the existing Java native driver. You can also create a connection entering a host, port, etc. as described in 'Connect Using the Dialog Fields'.

Tip You may connect to multiple servers or with different settings by choosing in Connection Dialog the 'Advanced' tab / Custom URL and use parameters as in http://docs.mongodb.org/manual/reference/connection-string/ . Please open this link in an web browser. We are passing the URL to the native MongoDb Java driver.

Connect Using MongoDb Native URI

You can connect using the same URI as in MongoDb documentation. Just enter this URI in DbSchema 'Advanced' tab and 'Custom URL'. You may connect to multiple hosts and use custom parameters. DbSchema JDBC driver is using the native MongoDb Java driver as described on http://docs.mongodb.org/manual/reference/connection-string/ .

Tip DbSchema features for MongoDb are explained in detail on https://www.dbschema.com/mongodb-tool.html as well as in the tutorials available on the same website, the tutorials page.

Connect Using the Dialog Fields

To connect to MongoDb you should first start from command prompt the mongod.exe process located in the MongoDb installation directory.

In the connection dialog you can enter the host, port, user and password ( by default not required ). From the Driver combo you can choose between connecting without authentication and with authentication.

The connection without authentication is the default one, unless you or an admin have set authentication on the server.



Connect to MongoDb Atlas Cloud

In Atlas choose 'Clusters' / 'Connect' and look for the Java URI connection string. Copy this value in the 'Advanced Tab' / 'Custom URL' field in DbSchema ( first tick the Use Custom URL checkbox ). This is the same procedure as in the Connect Using native Java URI chapter. For simplicity you can edit and use in the URI only the first server ( the URI contains a list of 3 servers ).

How to setup authentication in MongoDb server

To setup authentication in MongoDb follow this steps:
  1. Create the user in database:
    use admin
    db.createUser(
      {
        user: "test",
        pwd: "test",
        roles: [ { role: "root", db: "admin" } ]
      }
    );
     
  2. Create a file mongo.config in the MongoDB installation folder. Edit to
    # Basic database configuration
    dbpath = C:\data\db
    bind_ip = 127.0.0.1
    port = 27017
    
    # Security
    auth = true
    
    # Administration & Monitoring
    nohttpinterface = true
            
  3. Start the mongodemon using mongod.exe -f mongo.config. You can text the connection using mongo.exe --port 20571 -u test -p test --host 127.0.0.1 admin .