Using Meteor upsert with $inc

106 views Asked by At

I am struggling to get Meteor's collection.upsert method to work properly. Here is what I have:

const tagStatsId = TagStats.upsert({
  tag: tag
}, { 
  $inc: { count: 1 },
  $setOnInsert: { tag: tag, count: 0 }
});

I also have an upsert method to decrease the count by 1 (this could probably be an update method instead):

tagStatsId = TagStats.upsert({ 
  tag: tag 
}, { 
  $inc: { 
    count: -1,
  }
});

Right now, both methods are returning 0 for their result, which per the meteor docs should be an object. I am at a loss for why these methods aren't behaving properly.

It's worth noting I'm calling this method from a denormalizer method which fires after another object insert, but I don't think that should affect the behavior at all. I'm also using mdg:validated-method, but again, I don't think that should affect anything.

0

There are 0 answers