ios - 如何在数组上添加一个对象而不用firestore删除其余对象?
问题描述
我正在尝试在我的数组上添加一个对象。我的模型已经存在他是这样的:
function createUser () {
// User is signed in.
firestore()
.collection('Users')
.doc(user.uid)
.set({
NickName: nickName,
Age: age,
City:city,
Mail:mail,
Picture:'',
MyTeam:[{
Activity:"",
City:"",
adress:"",
text:"",
Members:[{
Picture:"",
Mail:"",
Pseudo:""
}],
Owner:true
}]
在“我的团队”对象上,我希望能够添加几个团队(如数组),但是当我尝试设置时,我的所有模型都被删除了。
async function RegisterTeam () {
// User is signed in.
firestore()
.collection('Users')
.doc(await AsyncStorage.getItem ('userID'))
.set({
MyTeam:[{
Activity:activity,
City:city,
Adress:adress,
text: text,
members: members,
Owner:true
}]
})
.then(() => {
console.log('team created !')
})
}
你知道我该怎么做吗?我正在反应原生 ios
解决方案
您可以使用.update()
代替.set()
. 为了不覆盖整个对象,您应该使用这样的点符号
firestore()
.collection('Users')
.doc(await AsyncStorage.getItem ('userID'))
.update({
"MyTeam.newTeamObj": {newObj}
})
https://firebase.google.com/docs/firestore/manage-data/add-data#update_fields_in_nested_objects
推荐阅读
- facebook - 登录失败:您无法使用 Facebook 登录此应用或网站,因为它的 Facebook 登录实现存在问题
- javascript - 在同一页面上为两个单独的画廊使用灯箱画廊代码?
- php - 如何使 do-while 循环完全不循环?
- php - 点击“下订单”后转换货币
- r - 为什么 ggplot2 在 geom_vline 的彩色线条之上添加黑线?
- c# - 提交表单并重定向后,MVC5 无法使用 ajax 获取 php api
- php - 比较2个数组并在php中回显数组相同内容的值的最佳方法是什么?
- python - Ubuntu 说 Python 是最新版本,但实际上不是。我如何更新它
- algorithm - 如何在有向图中找到彼此距离 k 的所有节点(探索图中的每条边)?
- java - 什么类型的数组(代码)适用于这个问题?