I'm using nano with couchDB, and I am just trying to do a simple update on a document to add a new field. For example, let's say I have a document called foo. The only field in it right now is 'bar', with some value. I then attempt to do db.insert with the code I'll post at the end, but instead of now having both fields, bar is erased, and I instead just have my new field. How can I fix this?
The code I'm using:
dB.get('foo', function(err, body) {
if (!err){
if(typeof body.qwax === 'undefined'){
dB.insert({qwax : [data], "_rev" : body._rev}, 'foo', function(err, body, header) {
if (err) {
console.log(err.message);
return;
}
});
}
else{
body.qwax.push(data);
dB.insert({qwax : body.qwax, "_rev" : body._rev}, 'foo', function(err, body, header) {
if (err) {
console.log(err.message);
return;
}
});
}
}
else{console.log(err);}
});
Where data is defined elsewhere.