Reactjs 如何将图像URL数组上载到Firestore?

Reactjs 如何将图像URL数组上载到Firestore?,reactjs,firebase,react-native,google-cloud-firestore,Reactjs,Firebase,React Native,Google Cloud Firestore,您好如何在react native中将图像URL数组上载到firestore 我试过这个 state = { photos: [] }; buttonPress() { const { photos } = this.state; firebase.firestore().collection('users').doc('images') .add({ photos }); } 但firestore数据库中的图像会显示如下 { "book": "Robin hood", "phot

您好如何在react native中将图像URL数组上载到firestore 我试过这个

 state = { photos: [] };

buttonPress() {

const { photos } = this.state; 

firebase.firestore().collection('users').doc('images')
.add({ photos });
}
但firestore数据库中的图像会显示如下

{
"book": "Robin hood", 
"photos": "https://picsum.photos/id/1001/5616/3744",
 }
我希望它在firestore数据库中以这样的数组显示

{
"book": "Robin hood", 
"photos":  [ "https://picsum.photos/id/1001/5616/3744"],
 }

这可以通过将
照片
包装在
[]
内部来实现。因此,您的代码将是

firebase.firestore().collection('users').doc('images')
  .add({ [photos] });
}
另外,如果您希望用户稍后添加而不是覆盖数组,我建议使用
set
merge:true

firebase.firestore().collection('users').doc('images')
  .set({ [photos] }, { merge: true });
}

这可以通过将
照片
包装在
[]
内部来实现。因此,您的代码将是

firebase.firestore().collection('users').doc('images')
  .add({ [photos] });
}
另外,如果您希望用户稍后添加而不是覆盖数组,我建议使用
set
merge:true

firebase.firestore().collection('users').doc('images')
  .set({ [photos] }, { merge: true });
}