加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 我可以在Firestore中更改文档的名称吗?

发布时间:2020-12-14 05:00:22 所属栏目:百科 来源:网络整理
导读:我目前正在开发一个应用程序,我必须从Google的Firestore中检索数据. 我的数据结构如下所示: users - name@xxx.com - more data 有没有办法让我将name@xxx.com改为名字? 我看不到改变文档名称的方法. 解决方法 我认为最好的方法是从’name@xxx.com’获取数
我目前正在开发一个应用程序,我必须从Google的Firestore中检索数据.

我的数据结构如下所示:

users
 - name@xxx.com
    - more data

有没有办法让我将name@xxx.com改为名字?
我看不到改变文档名称的方法.

解决方法

我认为最好的方法是从’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();
        });
    }
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读