firebase - 有没有办法创建 Auth 对象并使用该 UID 来创建带有 GeoFirestore 的文档
问题描述
我正在尝试在返回用户 UID 的 Firebase 中创建一个 Auth 对象。我希望能够使用该特定 UID 在我的集合中创建一个文档,但显然 geofirestore 没有添加具有特定 ID 的文档的功能。
const storesCollection = geoFirestore.collection("retailers");
export const firstTimeStartCreateRetailer = ( email, password) => async dispatch => {
try {
const { user } = await auth.createUserWithEmailAndPassword(email, password);
await storesCollection.doc(user.uid).add({
coordinates: new firebase.firestore.GeoPoint(33.704381, 72.978839),
name: 'Freshlee',
location: 'F-11',
city: 'Islamabad',
inventory: [],
rating: 5,
categories: []
})
dispatch({ type: LOGIN, payload: { ...user } });
} catch (error) {
console.log(error)
}
};
此代码被拒绝,因为 geoFirestore 没有 .doc(id) 引用功能。我怎样才能做到这一点。
解决方案
你需要做
await storesCollection.doc(user.uid).set({...})
使用set()
方法。事实上,没有add()
方法 aGeoDocumentReference
和storesCollection.doc(user.uid)
是 a GeoDocumentReference
。
该add()
方法是一种方法GeoCollectionReference
。
推荐阅读
- system-verilog - 多路复用通道中的 SystemVerilog 错误:实例数组的非常量索引
- jquery - 当点击下拉菜单打开所有子菜单
- squarespace - 在重复部分中输出 items.categories
- ruby-on-rails - 如何配置到sidekiq队列一次只运行任务
- javascript - 如何编写将替换 url 字符串中的密码的正则表达式?
- python - 无法结束多 if 语句以捕获所有
- ios - 返回UINavigationController时如何隐藏UITabBar
- python - 如何提取最高值并打印出最高值键?使用 for 或 while 循环
- sql - IBM SQL 求和和分组依据
- python - 硒使铬工艺保持开放