I have the following code:
var roomDoc = Rooms.findAndModify({
query: {name: roomName},
update: {$setOnInsert: {unixTimestamp: unixTimestampSeconds()}},
new: true,
upsert: true
});
After getting an error that .findAndModify is undefined
, I realized, Meteor doesn't implement .findAndModify
.
Is there a Meteor way to achieve similar functionality by using different queries?
However the answer above explains this specific case, in many other cases it is supposed that findAndModify
is an atomic operation that could be used for example to generate unique IDs:
http://docs.mongodb.org/v3.0/tutorial/create-an-auto-incrementing-field/
It seems that Meteor won't implement a wrapper of findAndModify
as a corresponding ticket is already closed, however the community proposed several solutions that already work on both server and client sides:
https://github.com/meteor/meteor/issues/1070
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With