Mongodb authentication with connection string

The connection string for the Mongo process has the / database option. What does it mean? Does this mean that it authenticates a specific database on the mongo server. thanks in advance

+3
source share
5 answers

With the C # driver, you usually will not use the ability to put the database name in the connection string. It is partially supported to provide some level of compatibility with other drivers.

MongoServer.Create ignores the database name. Any credentials (username / password) in the connection string are used as default credentials for all databases.

MongoDatabase.Create, MongoServer.Create, GetDatabase .

:

var connectionString = "mongodb://localhost/database";
var database = MongoDatabase.Create(connectionString);

:

var connectionString = "mongodb://localhost";
var server = MongoServer.Create(connectionString);
var database = server.GetDatabase("database");

, .

+5

:

var cliente = new MongoClient("mongodb://usuariocualquiera:tuclave@localhost:27017/BASEDEDATOS");

var collection = database.GetCollection<BsonDocument>("CUALQUIERCOLECCION");
+2

. , ,

0

/ mongod mongodb, admin mongodb localhost: 27017. Connect() - .

0

Assuming that a user account has been created in the administrator database, and assuming that you are using a command-line interface (CLI) program called "mongo", you can connect to 3-node replication with a username and password using the following:

Syntax:

mongo --host "<replicaset name>/<host 1 resolvable name>:<host 1 port>,<host 2 resolvable name>:<host 2 port>,<host 3 resolvable name>:<host 3 port>" --username <username> --password <password> --authenticationDatabase <database name>

Example:

mongo --host "replset1/ip-172-31-48-110.eu-west-1.compute.internal:27017,ip-172-31-116-186.eu-west-1.compute.internal:27017,ip-172-31-29-140.eu-west-1.compute.internal:27017" --username barry --password supersecretpassword --authenticationDatabase admin
0
source

All Articles