Command Prompt Tutorial


Commands (Cont. 1 )

You can check the no. of documents in a collection by using
> db.data.count()



Lets insert some documents into the collection "data", we have created
Just to clarify, our database name is data and our collection name is also data. 

( I should have used a different name for collection...my apologies...)


Syntax is:

db.collection_name.insert({"field":"value"});


>db.data.insert();

This is empty, which we have created.

So, lets insert some name

>db.data.insert({“name”:”abc”});

We can also specify multiple values for a single attribute.

>db.data.insert({“name”:”abc”,”ph”:[123,456]});



To check your documents in a collection, use the following command

>db.collection_name.find();




The unique ID above is generated based on the machine and current time. 
So, the combination of all these components makes a perfect unique key.









0 comments:

Post a Comment