mongoose-sequence icon indicating copy to clipboard operation
mongoose-sequence copied to clipboard

Doesn't work with findOneAndUpdate

Open dottodot opened this issue 7 years ago • 9 comments

I'm using findOneAndUpdate and upsert:true to do a findOrCreate buy my auto increment field is not being populated. It works when using create.

dottodot avatar Sep 08 '16 13:09 dottodot

There is an open PR (#10) on this problem. We still are not able to fix the problem mainly because of how mongoose hooks works for findOneAndUpdate.

ramiel avatar Sep 08 '16 13:09 ramiel

@ramiel what exactly is it that will have to be fixed before my PR can be merged?

Auto incrementation works fine in findOneAndUpdate using the code in my PR. The only "bad" thing I know of, is that it has to perform another find query in order to make it work. But until Mongoose can provide a way to avoid having to do that, I don't see another choice.

linusbrolin avatar Sep 21 '16 11:09 linusbrolin

There is a list on the PR. By the way:

  • Using multi: true during an update should work the same
  • The same functionality should work for referenced fields

I prefer to release the functionality when is complete. On the other side I had no time at all to look again at this

ramiel avatar Sep 21 '16 11:09 ramiel

Ok, I'll see if I can find some time to look at those points in the near future.

linusbrolin avatar Sep 21 '16 11:09 linusbrolin

Thank you. Your contribution is really appreciated!

ramiel avatar Sep 21 '16 11:09 ramiel

Any update in reference to #29, the same issue obviously occurs with bulkwrite. @ramiel

ptariche avatar May 08 '18 22:05 ptariche

The same issue is still there. Any update?

acskck avatar May 14 '20 05:05 acskck

any update ?

blocks-master avatar Aug 21 '20 14:08 blocks-master

Due to the way mongoose hooks work,it's not.possible to cover all the cases. I'll should probably find the time to cover at least the basic use case (no multi,no bulkwrite) but I have no time now,so I don't know when I can work on this again

ramiel avatar Aug 23 '20 19:08 ramiel