Android 实时更新仅返回已更改的文档,而不是整个查询

Android 实时更新仅返回已更改的文档,而不是整个查询,android,google-cloud-firestore,Android,Google Cloud Firestore,我正在使用Firestore实时更新,我有以下侦听器 CollectionReference collecRef = db.collection("lists").document("doc1").collection("locations"); changesListener=collecRef.addSnapshotListener(new EventListener<QuerySnapshot>() { @Override pu

我正在使用Firestore实时更新,我有以下侦听器

 CollectionReference collecRef = db.collection("lists").document("doc1").collection("locations");
changesListener=collecRef.addSnapshotListener(new EventListener<QuerySnapshot>() {
            @Override
            public void onEvent(@Nullable QuerySnapshot snapshots,
                                @Nullable FirebaseFirestoreException e) {
            if (e != null) {
                Log.w(TAG, "listen:error", e);
                return;
            }
            a
            for (DocumentChange dc : snapshots.getDocumentChanges()) 
            {
                DocumentSnapshot document = dc.getDocument();
             // this is where I expected to loop over all documents. But instead it is only one item..the changed the document

            }

        }
    });
CollectionReference collecRef=db.collection(“列表”).doc1.collection(“位置”);
changesListener=collecRef.addSnapshotListener(新的EventListener(){
@凌驾
public void onEvent(@Nullable QuerySnapshot快照,
@可为空的FireBaseFireStore异常(e){
如果(e!=null){
Log.w(标签“listen:error”,e);
返回;
}
A.
对于(DocumentChange dc:snapshots.getDocumentChanges())
{
DocumentSnapshot document=dc.getDocument();
//这是我希望在所有文档上循环的地方。但是它只是一个项目。更改了文档
}
}
});
根据文件:

查看查询结果之间的实际更改通常很有用 查询快照,而不是简单地使用整个查询快照

这意味着当一个文档被修改时,我希望整个查询重新运行,因为结果发生了变化。但是,在监听器中,我只获得已更改文档的文档快照,而不是所有查询结果(即我的案例中的所有文档)


我在这里遗漏了什么吗?

如果调用
snapshots.getDocumentChanges()
则只会得到已更改的文档。如果您想获取所有文档,请致电


您共享的代码对
QuerySnapshot
没有任何作用。你能分享再现问题的最小代码吗?这是侦听器的代码,它在更改时被调用。第一次打电话给它,它给了我21份详细的文件。当其中一个文档发生更改时,这只会给我一个文档。。。正在换的那个
for (Document document : snapshots.getDocuments()) {
    ... do something with document ...