How do i connect to existing mongodb?

I have mongodb server on my system. For testing purpose i created different database using different port. E.g.

  • dbname1 - SomepathIndrive -- Port
  • dbname2 - SomepathIndrive -- Port
  • dbname3 - SomepathIndrive -- Port

Now how do connect/start dbname2 or dbname 3 ?

When I use mongo command , it connects to default port and default database

asked Sep 21, 2017 at 6:52

3

As you said

mongo

command will connect to the server on the default port, if you want to connect to the server on different port use

mongo --port portnumber

When you are connected to mongo shell, command

show dbs

will result in list of all available databasses and to start using one of these use command

use databasename

Here's the link to the mongodb documentation about mongo Shell: https://docs.mongodb.com/manual/mongo/

answered Sep 21, 2017 at 8:37

Docs HomeMongoDB Manual

connect(url, user, password)

Creates a connection to a MongoDB instance and returns the reference to the database. However, in most cases, use the Mongo() object and its getDB() method instead.

Parameter

Type

Description

url

string

Specifies the connection string. You can specify either:

  • :/

  • /

user

string

Optional. Specifies an existing username with access privileges for this database. If user is specified, you must include the password parameter as well.

password

string

Optional unless the user parameter is specified. Specifies the password for the user.

The following example instantiates a new connection to the MongoDB instance running on the localhost interface and returns a reference to myDatabase:

db = connect("localhost:27017/myDatabase")

Tip

Navigation

You were redirected from a different version of the documentation. Click here to go back.

  • Create or Import a MongoDB Deployment >
  • Connect to a MongoDB Process

Overview¶

To connect to a MongoDB, retrieve the hostname and port information from Cloud Manager and then use a MongoDB client, such as mongosh or a MongoDB driver, to connect. To connect to a cluster, retrieve the hostname and port for the mongos process. To connect to a replica set or standalone process, retrieve the hostname and port for the mongod processes.

Firewall Rules¶

Firewall rules and user authentication affect your access to MongoDB. You must have access to the server and port of the MongoDB process. For information on firewalls on servers running MongoDB, see the firewall information in the Network Security document in the MongoDB manual.

If your MongoDB instance runs on Amazon Web Services (AWS), then the security group associated with the AWS servers also affects access. AWS security groups control inbound and outbound traffic to their associated servers.

Procedures¶

You can retrieve a shell command for connecting to your MongoDB instance, or you can retrieve the host and port number of a specific MongoDB process and create your own command for connecting using either shell or MongoDB driver.

Get a Shell Command to Connect to a MongoDB Instance¶

Navigate to the Clusters view for your deployment.¶

  1. If it is not already displayed, select the organization that contains your desired project from the office icon Organizations menu in the navigation bar.
  2. If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
  3. If it is not already displayed, click Deployment in the sidebar.
  4. Click the Clusters view.

On the line listing the cluster, replica set, or process, click the ellipsis icon and select Connect to this instance

Cloud Manager provides a mongo command that you can use to connect to the MongoDB process.

Get the Host and Port for a MongoDB Process¶

Navigate to the Clusters view for your deployment.¶

  1. If it is not already displayed, select the organization that contains your desired project from the office icon Organizations menu in the navigation bar.
  2. If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
  3. If it is not already displayed, click Deployment in the sidebar.
  4. Click the Clusters view.

(Optional) For sharded clusters, filter which process type is listed.¶

The four buttons are listed in the following order, left to right: Shards, Configs, Mongos, and BIs.

ProcessDisplays
Shards mongod processes that host your data.
Configs mongod processes that run as config servers to store a sharded cluster’s metadata.
Mongos mongos processes that route data in a sharded cluster.
BIs BI processes that access data in a sharded cluster.

On the line listing the process, click Metrics

Cloud Manager displays the hostname and port of the process at the top of the charts page.

Connect to a Deployment Using mongosh¶

Get the host and port using the previous procedure. From a shell, run mongosh and specify the host and port. For example:

mongosh --username  --password  --host  --port 

Connect to a Deployment Using a MongoDB Driver¶

Get the host and port using the above procedure. See your driver’s instructions for creating a connection string that specifies the hostname and port.

For sharded clusters, you specify the hostname and port of the mongos instance. For a replica set, you specify a seed list of all hosts in the replica set. Your driver will automatically connect to the primary. For example:

mongodb://[:@]hostname0<:port>[,hostname1:][,hostname2:][...][,hostnameN:]

How does MongoDB connect to existing database?

How to connect to existing mongodb database.
dbname1 - SomepathIndrive -- Port..
dbname2 - SomepathIndrive -- Port..
dbname3 - SomepathIndrive -- Port..

How do I access local MongoDB?

You can connect to a local MongoDB server running with its default configuration by typing:.
mongo. ... .
MongoDB shell version v4.4.6. ... .
mongo --username --password. ... .
MongoDB shell version v.4.4.6. ... .
mongo "mongodb://:@127.0.0.1" ... .
mongo. ... .
show dbs. ... .
use admin..

How do I access MongoDB from another computer?

MongoDB remote connection – Globally access.
Add global bindIp in mongod. config. MongoDB authentication - give auth ... ... .
AWS server side – give access permission TCP mongoDB port. In AWS dashboard navigate to. ... .
Connect to Database using MongoDB compass. Open db compass, connect > new Connection > Paste your connection string..

How do I connect to a MongoDB cluster?

You'll need to get your cluster's connection string from Atlas to connect to the cluster using the PyMongo driver..
Click Connect. ... .
Click Choose a connection method..
Click Connect your application. ... .
Select Python and your version of the driver. ... .
Copy the provided connection string..
Configure the provided connection string..