本文介绍了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更新
发布评论