mquery icon indicating copy to clipboard operation
mquery copied to clipboard

Add support for findOneAndReplace?

Open jrista opened this issue 7 years ago • 2 comments

I have been using Mongorito for some time now, and I really like it over some of the alternative node.js driver options out there. Mongorito uses mquery underneath the surface, which is great, since all of the mquery functionality is exposed.

I have on a growing number of occasions now run into a need for findOneAndReplace. This was added in MongoDB 3.2, and is one of the most useful update methods for me these days. I am not sure if there is a reason this operator has not been added, however i would love to see it added. I have multiple uses for it at the current time.

jrista avatar Jul 10 '18 22:07 jrista

Sounds good. Please submit a PR.

aheckmann avatar Jul 11 '18 15:07 aheckmann

You can use findOneAndUpdate with .setOptions({replace: true}) to achieve your goal. The replace option is only valid in mquery and support old MongoDB. It works as polyfill and maybe need to be updated to use latest driver version to enhance performance.

Fonger avatar Jul 31 '18 06:07 Fonger