0
var newBillObject = {
billId: Random.id(),
billAmount: bill.billAmount,
billDate: new Date()
};
var pointAdded = Math.round((bill.pointPercent/100) * bill.billAmount);
var data = Customers.findOne({ "phone": bill.phone });
if (data) {
var restaurantInfo = {
restaurantId: this.userId,
points: pointAdded,
createdAt: new Date(),
lastVisited: new Date()
};
Customers.update({ "restaurants.restaurantId": this.userId }, {
$push: { customerBills: newBillObject },
$set: { "restaurants.$.lastVisited": new Date() },
$inc: { "restaurants.$.points": pointAdded }
}, {
$setOnInsert: {
"restaurants.$.createdAt": new Date()
}
},{ upsert: true }
);
} else {
// return
// Customers.update({"restaurants.restaurantId":this.userId ,'phone':bill.phone}, {
var restaurantInfo = {
restaurantId: this.userId,
points: pointAdded,
createdAt: new Date(),
lastVisited: new Date()
}
return Customers.insert({
name: bill.name,
phone: bill.phone,
code: bill.code,
restaurants: [restaurantInfo],
customerBills: [newBillObject]
});
}
我想使用upsert更新現有客戶,如果restaurants.restaurantId
!= this.userId
但它不更新該客戶。插入新客戶並更新restaurantId==this.userId
工作正常的客戶。如何使用upsert更新數組中的對象?
我也做了相同的。 –
我可以在你的代碼中看到你在第四個括號中傳遞「upsert:true」。 –
okk ..感謝.. btw你知道任何方法如何上傳流星在Amazon S3上的圖像? –