What should I use besides .findAndModify?

I have the following code:

var roomDoc = Rooms.findAndModify({
  query: {name: roomName},
  update: {$setOnInsert: {unixTimestamp: unixTimestampSeconds()}},
  new: true,
  upsert: true
});

After receiving the error, which .findAndModify is undefined, I realized, Meteor does not implement .findAndModify.

Is there a Meteor way to achieve similar functionality using different requests?

+4
source share
3 answers

It is not obvious what to do alone find()and upsert()separately.

Rooms.upsert({name: roomName}, {$setOnInsert: {unixTimestamp: unixTimestampSeconds()}};
var roomDoc = Rooms.findOne({name: roomName});

This is probably a little less efficient due to two db calls, but if that bothers you, you just write your own meteor cover for Mongo findAndModify()using Room.rawCollection ().

0
source

, .

var roomDoc = Rooms.rawCollection().findAndModify(
  { name: name }, 
  [], 
  { $setOnInsert: {unixTimestamp: unixTimestampSeconds()} }, 
  { new: true, upsert: true }
)

:

https://forums.meteor.com/t/automatically-increment-order-numbers/11261/12

+2
source

All Articles