Mat*_*ten 12 swift google-cloud-firestore
我目前正在开发一个应用程序,我必须从Google的Firestore中检索数据.
我的数据结构如下所示:
users
- name@xxx.com
- more data
Run Code Online (Sandbox Code Playgroud)
有没有办法让我将name@xxx.com改为名字?我看不到改变文档名称的方法.
小智 10
我认为最好的方法是从'name@xxx.com'获取数据并将其上传到名为'name'的新文档,然后删除旧文档.
举个例子:
const firestore = firebase.firestore();
// get the data from 'name@xxx.com'
firestore.collection("users").doc("name@xxx.com").get().then(function (doc) {
if (doc && doc.exists) {
var data = doc.data();
// saves the data to 'name'
firestore.collection("users").doc("name").set(data).then({
// deletes the old document
firestore.collection("users").doc("name@xxx.com").delete();
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7432 次 |
| 最近记录: |