首页 > 解决方案 > 无法将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 对象,其中有数据。有没有人遇到过这个问题?

标签: firebasereact-nativegoogle-cloud-firestore

解决方案


根据我最初阅读的文档,您似乎只将坐标放在 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);
});

推荐阅读