Sunday, April 8, 2018

Basic Mongodb commands



Basic Mongodb commands with example

Create collection (Tables) (there is no create table command. 1st insert command will create table(collection)
======================================================================
db. student. insert({name:"sadakar",state:"telangana",city:"hyderabad"});

To display the data from collection
====================================== 
 db.student.find()
 db.student.find().pretty()

To display the data in array format (Case sensitive)
=================================
db.student.find().toArray();

update
=========
1)full document update i.e replace the document.
2)partial update i.e, update record.

t.update({_id:100},{"_id":100,x:hello world",y:123})
 ** id is the one of the key value and you cannot update the id value.

Remove
==========
db.test.remove({_id:100})
db.users.remove({ "addr.city": "Lyon", registered: false })

No comments:

Post a Comment