[DOCS-8133] Comment on: "manual/tutorial/enable-authentication.txt" Created: 20/Jun/16  Updated: 03/Nov/17  Resolved: 05/Oct/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Docs Collector User (Inactive) Assignee: Ravind Kumar (Inactive)
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Debian 7, MongoDB 2.4.10

Location: https://docs.mongodb.com/manual/tutorial/enable-authentication/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/50.0.2661.102 Chrome/50.0.2661.102 Safari/537.36
Referrer: https://www.google.es/
Screen Resolution: 1920 x 1080


Participants:
Days since reply: 7 years, 34 weeks, 2 days ago

 Description   

The information is outdated. I wasted long time trying to figure out and googling to find out that method "createUser" is deprecated and replaced by "addUser", as well as the format for roles (plain strings).



 Comments   
Comment by Ravind Kumar (Inactive) [ 20/Jun/16 ]

Hello,

db.createUser() is the currently supported method for adding users to a MongoDB database. It is possible that you are viewing an old or outdated page. If you found this information through a third-party website, it is possible the information is outdated or wrong.

The addUser() method has been deprecated since MongoDB 2.6. When you use plain strings to specify the built-in roles in 2.6+, it defaults to the database in use. To specify a database to add a role to, you can pass a document to the roles array as documented in createUser().

For MongoDB versions 2.6+, you can create users with db.createUser(), as in the following example:

use products
db.createUser( { user: "accountAdmin01",
                 pwd: "changeMe",
                 customData: { employeeId: 12345 },
                 roles: [ 
                             { role: "clusterAdmin", db: "admin" },
                             { role: "readAnyDatabase", db: "admin" },
                             "readWrite"
                           ] 
               },
               { w: "majority" , wtimeout: 5000 } )

This creates a user with clusterAdmin role on the admin database, readAnyDatabase role on the admin database, and readWrite role on the products database.

I hope this answers your question.

Generated at Thu Feb 08 07:55:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.