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]
});
}
restaurants.restaurantId
!= this.userId
の場合、upsertを使用して既存の顧客を更新したいが、その顧客を更新していない。新しい顧客を挿入し、restaurantId==this.userId
が正常に動作している顧客を更新する。upsertを使って配列内のオブジェクトを更新するには?
ように私は同じことを行っています。 –
私はあなたのコードで4番目の括弧で "upsert:true"を渡すことができます。 –
okk..Thanks .. btwアマゾンs3の流星で画像をアップロードする方法を知っていますか? –