[英]In Firestore, how do I change for all documents of a collection of which a certain field has a certain value, that field in a certain value?
如果某個字段等於某個值,我想將 Cloud Firestore 集合中所有文檔的某個字段的值更改為某個值。 我怎么做?
除了道格的回答,如果你想更新一個字段包含某個值的集合中的所有文檔,那么請使用以下代碼行:
FirebaseFirestore db = FirebaseFirestore.getInstance();
Query query = db.collection("collName").whereEqualTo("fieldName", "fieldValue");
query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
document.getReference().update("fieldToUpdate", "value");
}
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.