Categories
JavaScript Answers

How to update document by _id with Node.js node-mongodb-native?

Spread the love

To select document by _id with Node.js node-mongodb-native, we call the update method.

For instance, we write

const mongo = require("mongodb");
const id = new mongo.ObjectID(theId);
collection.update({ _id: id });

to create an object ID object with the ObjectID constructor.

And then we call update to update the document in the collection with the id _id value.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *