javascript - 无法在 firestore 中使用 set() 合并数据,而是覆盖数据
问题描述
我想在 Friends 集合中附加 UserId 文档,因为他们接受新的好友请求,但uid
文档中的字段被最近接受的好友请求覆盖。merge: true
尽管使用了我期望发生的事情,但我收到了这个错误:
Friends (collection)
userId (document)
uid: randomValue,
uid: randomValue,
.
.and so on
实际发生了什么:
我的代码:
const uid = auth().currentUser.uid;
function onAcceptRequest() {
firestore()
.collection('Friends')
.doc(`${uid}`)
.set(
{
uid: senderId,
},
{merge: true},
)
.then(() => {
firestore()
.collection('Friends')
.doc(`${senderId}`)
.set(
{
uid: uid,
},
{merge: true},
)
.then(console.log('Befriended'))
.then(() => deleteRequest())
.catch(err => console.log('senders err', err));
})
.catch(err => console.log('currentUsers err', err));
}
如果有任何其他方法可以完成同样的事情,那么请提出建议。谢谢你。
解决方案
推荐阅读
- python - Python tkinter - 即使使用多线程,GUI 也“滞后”
- python - 如何使用 Python Selenium 与不同格式的标题进行交互?
- lua - lua 序列化和反序列化具有函数值的表
- python-3.x - Peewee 查询 - 类型错误:“ModelCompoundSelectQuery”和“int”实例之间不支持“>”
- javacard - 如何自定义新安装的补充安全域 (SSD)?
- arrays - 在 C 中打印指针数组
- python - pyopengl 中的静态文本
- javascript - Lit-html 以 DOM 节点为目标
- sql - Snowflake - 通过自定义名称引用列组
- java - 连接池 - 如何找到 CallableStatement 使用连接池(特别是 HikariCP)?SQL Profiler 或 PerfMon 计数器?