为什么 mongodb return 更改流中的空实体?
Why mongodb return empty entities from change streams?
我在 mongodb 中有一个 collection 是用 changestream 观看的。
protected fun <DocTypeT : Any> startWatcher(collectionName: String, docTypeClass: KClass<DocTypeT>, operationTypes: List<MongoOperationType>, onCollectionChangeFunction: (DocTypeT) -> Unit) {
val changeStreamPublisher = dbClient.getCollection(collectionName, docTypeClass.java)
.watch(listOf(Aggregates.match(Filters.`in`("operationType", operationTypes.map { operationType -> operationType.value }.toList()))))
.fullDocument(FullDocument.UPDATE_LOOKUP)
changeStreamPublisher.withDocumentClass(docTypeClass.java).toFlux()
.subscribe(onCollectionChangeFunction)
}
我关注的事件是:“插入、更新、替换”。
事件是在函数中接收到的,但实体包括所有空字段(或例如原语的默认值)。
有没有办法获取我从变更流创建或更新的object?
我用 class 作为参数使用了 watch
方法的另一个重载并且它起作用了:
protected fun <DocTypeT : Any> startWatcher(collectionName: String, docTypeClass: KClass<DocTypeT>, operationTypes: List<MongoOperationType>, onCollectionChangeFunction: (DocTypeT) -> Unit) {
val changeStreamPublisher = dbClient.getCollection(collectionName, docTypeClass.java)
.watch(listOf(Aggregates.match(Filters.`in`("operationType", operationTypes.map { operationType -> operationType.value }.toList()))), docTypeClass.java)
.fullDocument(FullDocument.UPDATE_LOOKUP)
changeStreamPublisher.toFlux()
.subscribe(onCollectionChangeFunction)
}
我在 mongodb 中有一个 collection 是用 changestream 观看的。
protected fun <DocTypeT : Any> startWatcher(collectionName: String, docTypeClass: KClass<DocTypeT>, operationTypes: List<MongoOperationType>, onCollectionChangeFunction: (DocTypeT) -> Unit) {
val changeStreamPublisher = dbClient.getCollection(collectionName, docTypeClass.java)
.watch(listOf(Aggregates.match(Filters.`in`("operationType", operationTypes.map { operationType -> operationType.value }.toList()))))
.fullDocument(FullDocument.UPDATE_LOOKUP)
changeStreamPublisher.withDocumentClass(docTypeClass.java).toFlux()
.subscribe(onCollectionChangeFunction)
}
我关注的事件是:“插入、更新、替换”。
事件是在函数中接收到的,但实体包括所有空字段(或例如原语的默认值)。
有没有办法获取我从变更流创建或更新的object?
我用 class 作为参数使用了 watch
方法的另一个重载并且它起作用了:
protected fun <DocTypeT : Any> startWatcher(collectionName: String, docTypeClass: KClass<DocTypeT>, operationTypes: List<MongoOperationType>, onCollectionChangeFunction: (DocTypeT) -> Unit) {
val changeStreamPublisher = dbClient.getCollection(collectionName, docTypeClass.java)
.watch(listOf(Aggregates.match(Filters.`in`("operationType", operationTypes.map { operationType -> operationType.value }.toList()))), docTypeClass.java)
.fullDocument(FullDocument.UPDATE_LOOKUP)
changeStreamPublisher.toFlux()
.subscribe(onCollectionChangeFunction)
}