Types in latest mongodb nodejs driver v6.5.0

Hi, Currently we have mongodb v5.8 package installed. While upgrading to v6.5.0, i’ve encountered few typescript types issue for the package mongodb@6.5.0.

The objective is to get return type as ModifyResult.

So, below is the types specified for findOneAndUpdate methods:

And i’ve my configs like below:

const options = {
    includeResultMetadata: true

db.collection(collectionName).findOneAndUpdate(conditions, options)

While i do this, I’m getting a return type of WithId, even after specifying includeResultMetadata to true in the options.

Whereas, if i do like below, I’m getting the return type as ModifyResult which was our intention

db.collection(collectionName).findOneAndUpdate(conditions, options && { includeResultMetadata: true })

So, my question is, do we really need to add includeResultMetadata seperately inorder to get the return type as ModifyResult ??

Hi @Sooraj_S,

Once you have migrated to 6.0.0+, includeResultMetadata: false is the default behavior. If your application relies on the previous behavior of these APIs, setting includeResultMetadata: true will allow you to continue to access the ModifyResult directly. Please refer to the documentation to learn more.

Also, refer to this post to read more about the changes in Node.js Driver 6.0.0.

I hope it helps!

Best regards,

Hi, I’ve gone through the documentation and modified the functions.
But when i add the option includeResultMetadata in a variable and passing its not recognising.

I need to specify explicitly like the way its mentioned in the index.d.ts type file rather than including it in another variable along with other options.

Was this intentional?