flapdoodle-oss / de.flapdoodle.embed.mongo

...will provide a platform neutral way for running mongodb in unittests.
Apache License 2.0
907 stars 161 forks source link

Mongo Shell Support for MongoDB > 4.2 #524

Open michaelmosmann opened 3 months ago

michaelmosmann commented 3 months ago

Discussed in https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/discussions/522

Originally posted by **bendherville** June 13, 2024 Hi, We are upgrading embed.mongo in our application as we have recently moved from windows to mac (m3) for development and the v2 version of embed.mongo doesn't work with arm64. Previously we programatically used mongo shell to run some scripts to setup our DB before our integration tests were executed. I'm trying to do the same in v4.14.0 but I am getting an error when MongoShell is initialising. The code looks like; ``` public void runScript(String script, ServerAddress serverAddress) throws IOException { Transitions transitions = MongoShell.builder().build().transitions(Version.V7_0_11) .replace(Start.to(MongoShellArguments.class).initializedWith(MongoShellArguments.builder().scriptName(script).build())) .addAll(Start.to(ServerAddress.class).initializedWith(serverAddress)); try (TransitionWalker.ReachedState state = transitions.walker() .initState(StateID.of(ExecutedMongoShellProcess.class))) { // TODO: check state } } ``` and the error is; `java.lang.IllegalStateException: Cannot build ExtractedFileSet, some of required attributes are not set [executable]` But digging into it a bit, it appears it's downloading an archive and looking for a file named '.*mongo' with the archive. Presumably it's looking for the mongo shell command. The archive it's downloaded is `/Users/bend/.embedmongo/archives/https-fastdl-mongodb-org/56cb3d10404e5b9df5358ac4ee83efcb/osxmongodb-macos-arm64-7-0-11-tgz/bdaa5f3450eea95884efe91ca458f071e85217364d4d13665376dc8c51e1d319/archive.tgz` This contains mongod and mongos executables only. MongoShell is defaulting the Command to Mongo, which is where that .*mongo pattern is coming from. In newer versions of mongodb the mongo shell command is called mongosh and distributed separate from the database package so I guess this is why it's not working but not entirely sure. Can anyone confirm that MongoShell should work with mongo version v7_0 on MacOS?