Trying to update a document in mongodb using the following method :
module.exports.addAcc = function(id , acc, callback) {
let strAcc = escape(JSON.stringify(acc, null, 4));
let pushAcc = '{'+ ' $push :'+ '{ "pf.acc" : ' +strAcc + '}}' ;
let query = '{ "userid": ' + id + '}';
console.log('udpate <<',query,',' ,pushAcc, '>>'); <=====
Api.updateOne(query, pushAcc, {upsert: false}, callback);
};
it does give the following result :
{
"ok": 0,
"n": 0,
"nModified": 0
}
And When I catch what's in the console.log line and replace it in the Api.updateOne line, like this:
Api.updateOne({ "userid": 1197} , { $push :{ "pf.acc" : {"accid":1496998168,"accbr":65875}}}, {upsert: false}, callback);
it WORKS !!
{
"n": 1,
"nModified": 1,
"ok": 1
}
any idea why is that ?
/KOul
via K Oul
No comments:
Post a Comment