json - Update specific section of data in mongoDB using Node.js -



json - Update specific section of data in mongoDB using Node.js -

i looking modify 1 particular object within larger json object using mongodb , node.js. this:

{ "first": { "value": "v1", "status": "s1" }, "second": { "value": "v2", "status": "s2" }, "third": { "value": "v3", "status": "s3" } }

and want replace middle value this:

{ "second": { "value": "v2.2", "status": "s2.2" } }

at first thought this:

var db = require('mongodb').db var db = new db('database', new server('localhost', 27017), {safe:true}); var sec = { "second": { "value": "v2.2", "status": "s2.2" } } db.open(function(err, db){ db.collection('collection').update({}, second, {'upsert':true}, function(err, updated){ ... }

you can utilize $set operator update specific field second:

var sec = { "second": { "value": "v2.2", "status": "s2.2" }}; db.collection('collection').update({}, {$set: second}, function(err, updated){

json node.js mongodb

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -