addDeposit(account, deposit) {
let depositsDoc = this.db.collection("accounts")
.doc(account.id)
.collection("deposits")
.doc("deposits");
return new Promise((resolve, reject) => {
deposit.created_at = firebase.firestore.FieldValue.serverTimestamp();
depositsDoc.update({
"deposits": firebase.firestore.FieldValue.arrayUnion(deposit)
})
.then((a) => {
resolve('success');
})
.catch((error) => {
reject("failed");
});
})
.then((res) => {
return res;
})
.catch((error) => {
return error;
})
}
**使用默认的Firebase SDK而不是AngularFire与Angular一起使用Firestore**
我尝试通过直接添加“created_at”属性调用时间戳来向存款对象添加时间戳。这样做会导致上述错误。 在Firestore的对象数组中如何为对象添加时间戳?
serverTimestamp()
令牌被提供作为字段值(而不是数组元素)。 - Doug Stevenson