firebase - 无法将firestorage的url字符串添加到firestore
问题描述
我在向 Firestore 添加数据时遇到问题。如果来自 firestorage 的 URL 引用不在数据集中,我可以毫无问题地上传我的数据。我什至已经毫无问题地将空白文档上传到了 Firestore。大约 3 个月前我能够上传数据,但现在无法正常工作。
dbRef = firebase.firestore().collection('Collection');
const inputInfo = new GeoFirestore(dbRef);
inputInfo.add({
coordinates: new firebase.firestore.GeoPoint(this.state.latitude, this.state.longitude),
mainPhotoURL: this.state.mainPhotoURL,
address: this.state.address,
nickName: this.state.nickName,
firebaseID: this.state.firebaseID,
}).then((docRef) => {
console.log(docRef.id); // ID of newly added document
console.log(docRef);
}, (error) => {
console.log('Error: ' + error);
});de here
如果我取出主照片 URL,它将上传。如果我把它放在数据集中,那么它就不会添加到数据库中。我已经控制台记录了 mainphoto 对象,其中有数据。有没有人遇到过这个问题?
解决方案
根据我最初阅读的文档,您似乎只将坐标放在 geoFirestore 中。将您的元数据(例如昵称)放在单独的集合/文档中,并带有指向 geoFirestore uid 的指针。
GeoFirestore 实例用于在 Firestore 数据库中读取和写入地理位置数据并创建查询。
geoFirestore.set({ 'some_key': { coordinates: new firebase.firestore.GeoPoint(37.79, -122.41)}, 'another_key': { coordinates: new firebase.firestore.GeoPoint(36.98, -122.56)} }).then(() => { console.log('Provided keys have been added to GeoFirestore'); }, (error) => { console.log('Error: ' + error); });
推荐阅读
- python - 为什么我的 python 代码在 Visual Studio 上运行完美但在终端中中断?
- java - Spring Batch CommandLineJobRunner Config 类被忽略
- python - Pygame-太空侵略者子弹
- c++ - 从 QT 的 MainWindow 中的另一个函数更新标签
- javascript - Safari 中的 SVG 错误(使用 iframe 加载)
- reactjs - 使用酶设置 redux 连接反应组件的状态
- python - 重复调用 multiprocessing.Pool 实例
- monaco-editor - 如何添加sql提示提示
- css - 您将如何在 reactjs 应用程序中设置多个页面的“正文”而不使它们相互重叠?
- elasticsearch - 在 Elasticsearch 中,有没有办法获取字段超过 2 个值的文档