php - Firebase Firestore 添加数据而不覆盖

标签 php firebase google-cloud-firestore overwrite

我正在尝试将数据添加到我的 Firestore 数据库中。火炉是这样的:

Firestore 数据库

enter image description here

我有我的 php 文件,它使用此代码将数据加载到其中 db.collection('events').doc('documentNameUsingUniqueEventID').set({id1:data1, id2:data2, id3:data3, ...});
但是当我加载新数据并且旧数据仍然存在时,文档被覆盖并且我丢失了我所做的更改。有没有办法添加数据避免覆盖现有数据?

最佳答案

set() DocumentReference 上的方法具有 SetOptions 的第二个参数这允许您说要将数据合并到现有文档中而不是覆盖它:

db.collection('events')
    .doc('documentNameUsingUniqueEventID')
    .set(data, { merge: true });

关于php - Firebase Firestore 添加数据而不覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48626939/

相关文章:

php - 只更新一半数据到MySQL表

node.js - 语法错误 : Unexpected token 'const' -- despite the fact that I replaced const

go - 让Firestore将文档ID放在struct属性中

javascript - Reactjs dropzone未将所有拖放的文件上传到reactjs中的firebase firestore数据库

firebase - 无法在 Flutter 应用程序中通过用户 ID 获取特定用户文档

php - 使用 Pyrus 安装 ezComponents

php - Swift - 来自 PHP 的推送通知

javascript - 将 PHP 数组发送到 JS 模块, "import"问题

arrays - 如何从数组中删除 Firebase 快照?

firebase - Flutter的initState()不能立即检索数据,需要进行热重装才能查看