In NoSQL databases world there is no tables instead you store your data in collections which is similar to normal relation database table they are not really a table in structure but if you compare it with relation database you can do so with tables, collection in mongo is kind of scope which defines and control interaction with the documents and you issue commands against collection to store and retrieve data, because mongo is NoSQL database that means you cannot issue command across several collections like you do Joins in relation database.

So let’s save and create our first collection, you can do this by issuing the following command but make sure you selected the database you want to work in.

[php]
> Db.dbdiary.save({id:100, Name:”Niah”})
[/php]

When we issue this command Mongo will create a collection (table) for us by the name of dbdiary and then save two records in that collection (table) for us, to check if this was successful crated the record we issue the following command:

[php]
> db.dbdiary.find()
[/php]

What this command do is it will find the last line we just saved in the collection named (dbdiary) and display those records we saved before, now let’s issue a command to list all collection we currently have in our database.

[php]
> show collections
dbdiary
system.index
[/php]

as you can see we have two list one is the collection we just created (dbdiary) the other one is (system.index), there is rule in MongoDB which is every document we save must have an ID because what MongoDB does is it creates indexes on that ID so we can access our data faster.

Let’s take a look at Mongo system indexes by issuing the following command, what you will find in this is all your indexed created for each collection.

[php]
>db.system.indexes.find()
[/php]

This will display all indexes that is created for us automatically by mongo for each ID that we created in our documents this will be different depending upon how many collection you have and how many records you saved in your collections it will list all of them.

We can also find records more specifically like bellow to filter data more like (where) condition in normal relation database like bellow command:

[php]
>db.dbdiary.find( { id: 1 } )
[/php]

And we can also insert record in our currently existed collection as bellow:

[php]
db.products.insert( { id: 300, name: "Omer" } )
[/php]

This code will insert one record with the name (Omer) and id 300, these were some important operation like how to create and save records in MongoDB I will be going to create a more Advance CRUD for in next article make sure you subscribe, so you don’t miss any new posts.