Azure Data Engineer Online Training
- 12k Enrolled Learners
- Weekend
- Live Class
If you have been in the database management and programming industry for sometime now, you have probably heard about MongoDB. First introduced in 2009, MongoDB is currently one of the most popular relational database management software available in the market today. If you are new to using MongoDB, one of the first things you need to do is to create a user in MongoDB and then create a database likewise. In this article we will discuss about both.
Following pointers will be covered in this article,
In order to create a user in MongoDb, you need to make use of the createuser function. Take a look at the example shared below to understand how this is done.
db.createUser ( { user: "Edureka", pwd: "password", roles:[{role: "userAdminAnyDatabase" , db:"admin"}]})
Explanation
Let us breakdown the code shared above.
When the command is performed correctly, the output will look something like this.
Thus we have successfully created a user in MongoDB
Now let us see how to create a database in MongoDB
One of the most important things to note while creating a database in MongoDb is that, there is no special command or module that can be used to achieve this. While this might look strange if you have started using MongoDB after using other SQL database management systems where you need to create a database, create a table and then assign values within the same.
But in MongoDb, the database is automatically created by the system without any interference from the end user.
Another important thing to note here is that, you don’t need to specify what type of data you will be storing inside the database. The same will be automatically assigned once you have inputted the data into the created database.
Now that you know the basics, let us see how to create a database in MongoDb if none has been created automatically or you need to create an entirely new one.
In order to do this, you need to use the syntax,
use DATABASE_NAME
If the database you just entered already exists in the architecture, then you will be automatically switched and will start using the same. To understand this better, take a look at the example below.
>use javatpointdb
The output will look like this
Swithched to db javatpointdb
If you want to see the database you are currently using, then use this command.
>db
If you want to view a list of the entire databases that exist within the architecture, use this command.
>show dbs
If you want to insert a new list into a database that already exists then make use of this command.
>db.movie.insert({"name":"javatpoint"})
The above is an example and the parameters can be changed depending upon your needs.
If in a certain situation, you want to develop a user for a single database you need to make use of the userAdmin module.
As you can see in the image above, we have made use of the following code.
db.createUser ( user: "Employeeadmin", pwd: "password", roles:[{role: "userAdmin" , db:"Employee"}]})
Explanation
When the above code is run successfully, the output will look something like this.
The above example shows the creation of a user name – EmployeeAdmin and that it has permission to use the database Employee.
This brings us to the end of this article on Create User In MongoDB.
For details, You can even check out tools and systems used by Big Data experts and its concepts with the Data engineer online course.
Now that you have understood what is Big Data, check out the Big Data training by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. The Edureka Big Data Hadoop Certification Training course helps learners become expert in HDFS, Yarn, MapReduce, Pig, Hive, HBase, Oozie, Flume and Sqoop using real-time use cases on Retail, Social Media, Aviation, Tourism, Finance domain.
Got a question for us? Mention them in the comments section and we will get back to you.
edureka.co