Findoneandupdate return value property no longer exists

Hello; I just updated my nodejs driver ‘mongodb’ package from 4.x to 6.3, and now it seems findoneandupdate no longer returns a ‘value’ property with the modified/original document, but instead returns the document directly.
My entire codebase expects .value from every result of findoneandupdate, so this is a major issue. Has anyone else experienced this?..

Hey @Chris_Esperian, this was changed in 6.0.0 (see blog post).

You can use the includeResultMetadata option in your findOneAnd* operations to continue to use the previous behavior.

Thanks, man!
Very much appreciated…

FWIW, if you’re performing multiple major version upgrades we do have a summary of breaking changes at https://www.mongodb.com/docs/drivers/node/current/upgrade/#breaking-changes.

This is extremely useful, thank you!

I see changes to includeResultMetadata mentioned as a breaking change, but tbh I did not know this option even existed before, so I would have not had an idea as to what the change would impact and probably would not have given it much consideration. ‘Compound operations’ mentioned is a good indicator for the more db-oriented people, but it would be nice to see an example mentioned also for those of us less seasoned. ie; it would have caught my notice if ‘findoneandupdate’ would be mentioned as an example of a compound operation affected by this change.

Thanks again for the assist!!

Happy to help. Additionally this would have been mentioned in the changelog for 6.0 when it was released (Release v6.0.0 · mongodb/node-mongodb-native · GitHub), but I can see how this could get buried as well.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.