Is there a recommended solution on how to enable mongoDB "change streams" ?
michaelmosmann opened this issue · comments
Discussed in #496
Originally posted by bodote November 15, 2023
MongoDB has a feature called "change streams". However, this feature is only available if there is a "replica set". The replica set in turn is NOT enabled by default for single instance MongoDBs. You can enable the replica set with de.flapdoodle.embed.mongo. But it seemes a little bit cumbersome though.
Is there any recommendation on how to use this with de.flapdoodle.embed.mongo ?
what we do is this:
@Override
public Transition<MongodArguments> mongodArguments() {
return Start.to(MongodArguments.class)
.initializedWith(MongodArguments.defaults()
.withReplication(Storage.of("testRepSet", 5000))
.withUseNoJournal(false));
}
plus :
mongoClient.getDatabase("admin").runCommand(new Document("replSetInitiate", new Document()));
immediately @BeforeEach
test.
especially the need for this admin - command above turned out to be somehow problematic and lead to unstable test until we wraped it part of the test code in some await().atMost(10, SECONDS).until(() -> {...}
Is there any better way ?
Setting de.flapdoodle.mongodb.embedded.storage.repl-set-name=rs0
in the application.properties
when using de.flapdoodle.embed.mongo.spring
enables replicasets in a way that transactions seem to work. Maybe this does the trick here too?
@XSpielinbox you are right, if you use the spring integration: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/041421695626591599798602a39df8a61e3fdb42/src/main/java/de/flapdoodle/embed/mongo/spring/autoconfigure/AbstractServerFactory.java#L84
maybe it is time for an backport:)
@XSpielinbox you are right, if you use the spring integration: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/041421695626591599798602a39df8a61e3fdb42/src/main/java/de/flapdoodle/embed/mongo/spring/autoconfigure/AbstractServerFactory.java#L84
maybe it is time for an backport:)
If its already in the spring3.1.x branch of https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/ , which I use anyhow, it would be nice, if there would be an explationaion in the HowTo.md how to use this autoconfigure/AbstractServerFactory, because it is not clear to me.
Is setting the de.flapdoodle.mongodb.embedded.storage.repl-set-name=rs0
really all you need to do ?
@bodote yes.. the setting is all you need, as everything else will be configured from that (using AbstractServerFactory etc).
de.flapdoodle.mongodb.embedded
I see, thank you.
BTW using "de.flapdoodle.mongodb.embedded." and "de.flapdoodle.embed.mongo." for properties is really confusing, and can easily get mixed up which would lead to wrongly setting properties which are not working.
@bodote hmmm.. i may fix this with the next mayor release.. i think it was 'spring.mongodb.embedded' .. and i changed it to 'de.flapdoodle.mongodb.embedded' ..
moved it to an new issue.. so i close this.