So when you are working with MongoDB you have to learn how you can work with databases, create them and switch between the different databases. When you login to a MongoDB you most likely would like to know which databases are currently in MongoDB. To get a list of all databases you can use "show dbs"
> show dbs
admin (empty)
callreg 0.0625GB
local (empty)
test 0.0625GB
>
local, test and admin are installed by default, the callreg database is something I created to do some testing. If you want to switch between one database and another you can use the command "use
> use callreg
switched to db callreg
>
Now lets say we want to create a new database specially for handling shipping data, we will name it shipping. Basically you do not create a database within MongoDB as such. you can just switch to the (not yet existing) database by using the command "use shipping". This will bring you to the database shipping. Now if we insert data into this database it will be directly created. In the below example you see that we switch to the shipping database (which is not existing yet) and insert a document.
> use shipping
switched to db shipping
>
>
> db.shipping.insert({"shipping_number" : "1045", "receivedate" : "12-FEB-2011"})
>
if we nog check the list of databases using the "show dbs" command you will see that the database is created.
> show dbs
admin (empty)
callreg 0.0625GB
local (empty)
shipping 0.0625GB
test 0.0625GB
>
This is how you quickly create a new database, switch to the database (even if is not yet existing) and insert something into the database.
5 comments:
Thanks for the quick reference.
great one!. one question here
> db.shipping.insert({"shipping_number" : "1045", "receivedate" : "12-FEB-2011"})
Here, Is shipping is db name?. If yes. then on what table does this row gets inserted? Or what is table name?
> db.shipping.insert({"shipping_number" : "1045", "receivedate" : "12-FEB-2011"})
Here in db.shipping.insert command. Is shipping is db name Or table name?
Shipping is table name.
how to create a 100GB database for mongodb
Post a Comment