MongoDB Node Driver UpdateOne Promise Parameters

MongoDB Node Driver UpdateOne Promise Parameters

I am confused about the parameters that are passed through to the promise function of write operations.

I am confused about the parameters that are passed through to the promise function of write operations.

For example, the docs for updateOne say that the callback is an instance of updateWriteOpCallbackwhich has parameters error and result.

db.collection.('my-collection')
    .updateOne({_id: someObjectID}, {$set: someChanges}, function(err, result){
        console.log(err); //null
        console.log(result); //CommandResult
    }

In the above example, if the operation is successful, err is correctly set to null and result contains the result.

However, if I choose to us a promise instead of a callback:

db.collection.('my-collection')
    .updateOne({_id: someObjectID}, {$set: someChanges})
    .then((err, result) => {
        console.log(err); //CommandResult
        console.log(result); //undefined
    }

The first parameter err is actually giving me what should be in result, and result is undefined. Is there an explanation for why this happens?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

How to Use Express.js, Node.js and MongoDB.js

In this post, I will show you how to use Express.js, Node.js and MongoDB.js. We will be creating a very simple Node application, that will allow users to input data that they want to store in a MongoDB database. It will also show all items that have been entered into the database.

Build a REST API using Node.js, Express.js, Mongoose.js and MongoDB

Node.js, Express.js, Mongoose.js, and MongoDB is a great combination for building easy and fast REST API. You will see how fast that combination than other existing frameworks because of Node.js is a packaged compilation of Google’s V8 JavaScript engine and it works on non-blocking and event-driven I/O. Express.js is a Javascript web server that has a complete function of web development including REST API.

Node.js, ExpressJs, MongoDB and Vue.js (MEVN Stack) Application Tutorial

In this tutorial, you'll learn how to integrate Vue.js with Node.js backend (using Express framework) and MongoDB and how to build application with Node.js, ExpressJs, MongoDB and Vue.js