I'm using MongoDB to do data persistence in my application, with NodeJS.
I make the call like this:
module.exports = function (app) {
var dbConfig = app.config.db;
return {
changeAccountStatus: function (request, response, next, obj) {
dbConfig.mongoclient.connect(dbConfig.mongourl, function(err, db) {
if (err) {
console.log(err);
db.close();
}
else{
var dbo = db.db(dbConfig.mongodbname);
dbo.collection("driver").updateOne({_id: obj._id}, {$set: {accountstatus: obj.accountstatus}}, function(err, result) {
//Código do handler
});
db.close();
}
});
}
}
}
Sending a JSON via POST:
{
"_id":"5a7234ee869cd6058834acae",
"accountstatus":"active"
}
The field $filter
of updateOne
would be: { _id: '5a7234ee869cd6058834acae' }
And $update
: { '$set': { accountstatus: 'active' } }
In my opinion, the code is all right; I send an existing ID along with the new accountStatus
I want to change. But I always get the message.
{ n: 0, nModified: 0, ok: 1 }
Nothing has been modified. I do not know what I'm doing wrong.