Hi,
I want to try out getting a $changeStream of inserts into a collection,
but when I try to run the following simple code an "IllegalStateException: Invalid Map type. Map must have two type parameters defined." is thrown (see end of post for stacktrace):
MongoClient mongoClient = MongoClients.create(new ConnectionString("mongodb://localhost:27017"));
MongoDatabase database = mongoClient.getDatabase("mydb");
MongoCollection<Document> collection = database.getCollection("some-collection");
collection.watch(asList(
Aggregates.match(and(asList(
in("operationType", asList("insert")),
eq("fullDocument.even", 1L)))
)));
I am not sure what the problem is, I have tried the mongodb-driver and mongodb-driver-async libraries in version 3.6.0 and 3.6.1.
I also have included spring-boot-starter-data-mongodb-reactive, as I want to use the spring data repositories for most of the other queries. Can there be some conflict with that library?
I am not using MongoDB regularly, so I suspect the problem lying with me, but the ChangeStream feature seems to pretty new as well, so I couldn't really find anything on this particular issue on Google.
The following exception is raised (no matter which overloaded version of .watch I try to invoke):
java.lang.IllegalStateException: Invalid Map type. Map must have two type parameters defined.
at org.bson.codecs.pojo.TypeData$Builder.validate(TypeData.java:115) ~[bson-3.5.0.jar:na]
at org.bson.codecs.pojo.TypeData$Builder.build(TypeData.java:104) ~[bson-3.5.0.jar:na]
at org.bson.codecs.pojo.PojoBuilderHelper.getTypeData(PojoBuilderHelper.java:158) ~[bson-3.5.0.jar:na]
at org.bson.codecs.pojo.PojoBuilderHelper.getTypeData(PojoBuilderHelper.java:179) ~[bson-3.5.0.jar:na]
at org.bson.codecs.pojo.PojoBuilderHelper.configureClassModelBuilder(PojoBuilderHelper.java:69) ~[bson-3.5.0.jar:na]
at org.bson.codecs.pojo.ClassModelBuilder.<init>(ClassModelBuilder.java:59) ~[bson-3.5.0.jar:na]
at org.bson.codecs.pojo.ClassModel.builder(ClassModel.java:63) ~[bson-3.5.0.jar:na]
at com.mongodb.client.model.changestream.ChangeStreamDocumentCodec.<init>(ChangeStreamDocumentCodec.java:46) ~[mongodb-driver-core-3.6.0.jar:na]
at com.mongodb.client.model.changestream.ChangeStreamDocument.createCodec(ChangeStreamDocument.java:142) ~[mongodb-driver-core-3.6.0.jar:na]
at com.mongodb.async.client.ChangeStreamIterableImpl.<init>(ChangeStreamIterableImpl.java:62) ~[mongodb-driver-async-3.6.0.jar:na]
at com.mongodb.async.client.MongoCollectionImpl.createChangeStreamIterable(MongoCollectionImpl.java:378) ~[mongodb-driver-async-3.6.0.jar:na]
at com.mongodb.async.client.MongoCollectionImpl.watch(MongoCollectionImpl.java:350) ~[mongodb-driver-async-3.6.0.jar:na]
at com.mongodb.async.client.MongoCollectionImpl.watch(MongoCollectionImpl.java:345) ~[mongodb-driver-async-3.6.0.jar:na]
at com.mypackages.SomeController.test(SomeController.java:63) ~[classes/:na]