Meteor Mongo does not have findAndModify support - how to generate atomic counters?


#1

As per this Github issue:

https://github.com/meteor/meteor/issues/1070

Meteor does not or intend to add support for findAndModify, which is the method required to genenrate atomic counters, as per:

https://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/

How do I get around this?


Meteor Forums: "I'm not dead!"
#2

As long as you only need it in server code, you can do it like this:


#3

Thanks Rob. I mananged to find a package that does this for me:

https://atmospherejs.com/fongandrew/find-and-modify


#4

Unfortunatly this package does not work after upgrading to 1.4.1


#5

Has anyone found a package that works with 1.4.1?

Edit: Have looked into the new return value from the node mongo drivers and the desired result is now under .value field. There’s an open PR to keep the package updated but for now you can read from that value if you are in a hurry.


#6

Yes, I had the same problem and that is the solution.