Cloud Firestore更新

编程入门 行业动态 更新时间:2024-10-28 12:18:39
本文介绍了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更新

本文发布于:2023-11-22 05:13:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Cloud   Firestore

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!