mongoUpdate not updated


I running nodejs - mongoUpdate function with:

            let uresult = await mongo_dal.mongoUpdate({"_id": user._id}, {"sent": user.sent });

async function mongoUpdate(query, newData){
        let result = new Promise((resolve, reject)=>{
            const users = db.collection('users').updateOne(query,{$set: newData}, function(err, docs) {
                if (err) {
                } else {
        return result;
        return err.message;

on the “uresult.result.nModified” I got 1 - looks like all right and updated.
but really the data not updated!
the problem happens not always…

Please help me to solve this…

Hi @Anton_Turbin,

The user._id variable that you’re using in the filter portion of your updateOne operation. What format is the data?

If the value is a hash, you might try wrapping it in an ObjectID first so that the type is correct.

You’d import it like this:

const { MongoClient, ObjectID } = require("mongodb");

And when you want to use it, you’d do something like this:

mongoUpdate({ "_id": ObjectID(user._id) }, {"sent": user.sent });

This of course assumes that the problem was in the type of data that you’re using for your _id field.

Let me know if that helps.