MongoDB Roles - user access multiple databases

Mouette

I would like to give acces to a user to 2 databases in MongoDB.

I tried this, but it only give access to the admin db.

use admin;
db.runCommand(
{
    createUser: "myuser",
    pwd : "mypwd",
    roles: 
    [
        { role: "readWrite", db: "db1" } ,
        { role: "readWrite", db: "db2" } 
    ]
});

I tried to create the user on each db, but i end up with 2 users: user@db1 and user@db2

Any suggestions?

Markus W Mahlberg

Users can basically be saved in any database, which is why you can provide --authenticationDatabase on the command line tools, for example.

Taking the example for the cli, your command line should look something like this

mongo yourhost:yourport/db1 -u myuser --authenticationDatabase admin -p

and

mongo yourhost:yourport/db2 -u myuser --authenticationDatabase admin -p 

respectively, where you obvisouly have to substitute yourhost and yourport for actual values.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Is it possible to create a MongoDb user with multiple roles in Java?

Multiple MongoDb databases configuration

Multiple User Roles in Authorize

SQL Server 2008 RS Roles multiple databases

If the user has multiple roles, how to let the user choose one role to access to the application?

Multiple roles in 'User.IsInRole'

Spring security access with multiple roles

MongoDB custom user roles - "user is not allowed(...)"

MSSQL: List database membership roles of each user in several databases

User with multiple roles and multiple teams database design

Multiple Roles for a User belonging to multiple Organizations

Configure MongoDB 3 user roles in SaltStack SLS

RestHeart ACL - User access controls for databases

How to use <sec:authorize access="hasRole('ROLES)"> for checking multiple Roles?

Is a user with "Contributor" and "User Access Administrator" roles same as a user with "Owner" role?

Multiple databases with Spring Boot MongoDB Repositories dynamically

Using Multiple Mongodb Databases with Meteor.js

how to Assign Multiple Roles for a user in wordpress?

API - Multiple requests vs separating user roles

How to assign Multiple roles to a single user in wordpress

Rolify Assign Multiple User Roles at Once

Middleware on route level based on multiple user roles

Yii - multiple databases with one user authentication

Access multiple databases using fluent nhibernate in .netcore

MS access report combining multiple databases

Design of DAO to access multiple identical databases

How to run multiple mongodb databases with same name on single mongodb instance?

Concurrency and multiple user access

Return multiple roles for user in 1 column not multiple rows