Cloud Firestore更新 [英] Cloud Firestore Update

查看:49
本文介绍了Cloud Firestore更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据文档中的值更新Cloud Firestore中的文档.这样的事情.我很少有带有随机名称和值的文档,还有一个带有值 id = 1 name = patryk 的文档.现在,我要使用 name = patryk 更新文档.而且我不知道文档名称,因为我使它们像这样,并且它们具有随机名称.

I'd like update document in cloud firestore according to value in document. Something like this. I have few documents with random names and values and one document with values id = 1 , name = patryk . And now I'd to update document with name=patryk. And I don't know document name because I make them like this and they have a random name.

b.collection("Users")
    .add(postMapa)
    .addOnCompleteListener

如何执行此操作?此处我需要文件的名称,但我不知道没有.

How to do this? here I need have the name of the document but I don't have.

推荐答案

尝试此操作,确保只有名称= patryk的单个文档

  db.collection("Users").whereEqualTo("name", "patryk").addSnapshotListener(new EventListener<QuerySnapshot>() {
            @Override
            public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
                if (e == null) {
                    String documentId = queryDocumentSnapshots.getDocuments().get(0).getId();
                   // here you have id but make sure you have only one document for name=patryk
                }
            }
        });

这篇关于Cloud Firestore更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆