aroundtheworld
aroundtheworld

Reputation: 782

Setting whole doc and a specific value with one action mongoDB / meteor

At present I'm doing this to update a Collection whenever a webhook is fired indicating changed object data:

Products.update( {id: shopifyID }, { $set: doc });
Products.update( {id: shopifyID }, { $set: { lowestPrice: lowestPriceVariant(doc) }});

However, I'm trying to achieve that with just one update call. The first is setting the object to whatever object is returned by a webhook, which is why there is no mapping of key/value. Is this possible with mongoDB? So far, any combination I have tried only updates lowestPrice.

Upvotes: 0

Views: 22

Answers (1)

Marcin Hagmajer
Marcin Hagmajer

Reputation: 111

How about:

doc.lowestPrice = lowestPriceVariant(doc);
Products.update( {id: shopifyID }, { $set: doc });

Upvotes: 1

Related Questions