DocumentSnapshot MetaData字段hasPendingWrites == true,而父QueryDocumentSnapshot MeteData hasPendingWrites = false

时间:2018-10-11 22:57:58

标签: android firebase google-cloud-firestore

我观察到,使用实时查询更新时,Android Firestore SDK中的DocumentSnapshot MetaData字段hasPendingWrites == true,而父QueryDocumentSnapshot MetaData hasPendingWrites = false。这很奇怪,因为我想在文档更改的任何时候检查单个DocumentSnapshot是否有挂起的写操作。

listenerRegistration = FirestoreUtils.getMessagesCollection(chatId)
            .addSnapshotListener(MetadataChanges.INCLUDE) { snapshot, exception ->
                if (exception != null) {
                    Timber.w("An error occurred while trying to load messages: $exception")
                    return@addSnapshotListener
                }

                Timber.d("Snapshot Meta: ${snapshot?.metadata}")

                snapshot?.documentChanges?.forEach { doChanges ->
                    when (doChanges.type) {
                        DocumentChange.Type.ADDED -> {
                            Timber.d("Doc Added: ${doChanges.document}")
                        }
                        DocumentChange.Type.MODIFIED -> {
                            Timber.d("Doc Modified: ${doChanges.document}")
                        }
                        DocumentChange.Type.REMOVED -> {
                            Timber.d("Doc Removed: ${doChanges.document}")

                        }
                    }


                }

由于添加了此选项:MetadataChanges.INCLUDE,也会使用日志触发元数据更改事件,因此您可以看到,forQuery循环之前的out日志为false,而QueryDocumentSnapshot的各个文档的haspendingWrites为true。

所以问题是为什么元更改事件不触发文档更改?是否有找到导致元数据更改的文档的方法?

0 个答案:

没有答案