top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

MongoDB : Is mongoDB support to add a new (key:value) pair for an existing document ?

+1 vote
515 views

Query description: I have a collection name student_db and added a document in a collection with entries (name: "alok, age : 31 and profession: "xyz"). After inserting the document into student_db database, I want to add another (key:value ) pair i.e. salary: 50000.

Can someone help me out to resolve this problem ?

posted Jul 18, 2015 by Alok

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

yes it supports,If you want to add more {"key":"value"} pair in your collection of student_db,use update method and set the criteria which will specify the document id. This update command will not find any data to replace and It will add given {"key":"value"} pair to the document of specified collection.
Here is script Sample:
->use student_db;
->db.SampleCollectionName.update({"_id":ObjectId("DocumentID")},{$set:{"salary":50000}});

answer Jan 29, 2016 by Shivam Kumar Pandey
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...