Typescript 保存到firestore时出错
保存到firestore并随后检索该数据时出现问题。下面是失败的代码示例。这段代码非常基本,我的网络连接也很好。升级到websdk 5.0.4也无法解决此问题Typescript 保存到firestore时出错,typescript,firebase,google-cloud-firestore,Typescript,Firebase,Google Cloud Firestore,保存到firestore并随后检索该数据时出现问题。下面是失败的代码示例。这段代码非常基本,我的网络连接也很好。升级到websdk 5.0.4也无法解决此问题 save = async (data: any) => { try { const { id, ...rest } = data; await db .collection('/customers') .doc(id) .set({ ...rest })
save = async (data: any) => {
try {
const { id, ...rest } = data;
await db
.collection('/customers')
.doc(id)
.set({ ...rest });
const saved = await db
.collection('/customers')
.doc(data.id)
.get();
console.log(saved.data());
} catch (error) {
console.log(error);
}
};
在调试模式下,我看到以下内容:
[2018-05-28813:09:19.910Z]@firebase/firestore:firestore(5.0.3)[PersistentStream]:关闭时出错:FirebaseError:[代码=未知]:获取身份验证令牌失败:无法重新定义属性:\u lat
index.esm.js:65[2018-05-28813:09:19.915Z]@firebase/firestore:firestore(5.0.3)[指数退避]:退避46014.29558926278毫秒(基本延迟:60000毫秒)
index.esm.js:65[2018-05-28813:10:06.122Z]@firebase/firestore:firestore(5.0.3)[PersistentStream]:关闭时出错:FirebaseError:[code=unknown]:获取身份验证令牌失败:无法重新定义属性:\u lat
在firestore DB中插入数据并检查响应的一个简单示例:
//---creating reference---
const customRef = this.db.collection('customers');
//---inserting in DB---
customRef.set({
name: 'someName',
status: true,
}).then(response => {
console.error('response: ', response);
})
.catch(function (error) {
console.error('Error: ', error);
});
如果firebase console数据库中的规则为测试配置,也请检查:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
我首先要检查两件事-1。
数据中有什么?可能该对象包含无法持久化到Firestore的类型的内容?2.你有什么安全规则?@Ohad。数据是一个简单的对象
{name:'…',number:'…}。更奇怪的是实时数据库很好,auth很好。对于其他服务,配置中没有什么不同。规则很好。