 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I use a script to create users in MongoDB?
You can use createUser() method for this. Following is the syntax −
db.createUser(    {       user: "yourUserName",       pwd: "yourPassword",       roles: [ { role: "read", db: "yourDatabaseName" } ]    } ); Let us create a user in MongoDB. Here, we are using database ‘test’ −
> db.createUser( ...    { ...       user: "David", ...       pwd: "David123456", ...       roles: [ { role: "read", db: "test" } ] ...    } ... ); This will produce the following output −
Successfully added user: {    "user" : "David",    "roles" : [       {          "role" : "read",          "db" : "test"       }    ] }Advertisements
 