boooni boooni - 1 year ago 57
Node.js Question

Why getting error when updating MongoDb?

I am building backend with MEAN stack, but when I try to update document in the db i am getting an error:

topUp = function(name, amount, callback) {
{ "name" : name },
{ $set: { "wallet": amount } },
function(err, results) {

TypeError: User.updateOne is not a function

But e.g. findOne() works fine:

}, function(err, user) {
if (err) throw err;


f (!user) {
return res.status(403).send({success: false, msg: 'Authentication failed. User not found.'});
} else {
//res.json({success: true, info: {wallet: user.wallet, userPic: user.userPic}});
topUp(, amount, function() {

"User" is a Mongo model file.

Answer Source

I think it's not defined in the database driver that you might be using. I think you are using Mongoose and updateOne() is not available there. You cannot use all native mongodb functions with all drivers

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download