Add MongoDB shell version detection to before scripts
Update before_script.sh and before_script_docker.sh to automatically detect and use the appropriate MongoDB shell command (mongo or mongosh) based on availability. This ensures compatibility with both: - Legacy MongoDB versions using 'mongo' shell - Modern MongoDB versions (5.0+) using 'mongosh' The scripts now: - Check for command availability - Use the appropriate shell - Exit with helpful error if no shell is found
This commit is contained in:
parent
182a3a6f0b
commit
705f4d6f47
2 changed files with 28 additions and 8 deletions
|
|
@ -1,8 +1,18 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Check which MongoDB shell is available
|
||||||
|
if command -v mongosh >/dev/null 2>&1; then
|
||||||
|
MONGO_SHELL="mongosh"
|
||||||
|
elif command -v mongo >/dev/null 2>&1; then
|
||||||
|
MONGO_SHELL="mongo"
|
||||||
|
else
|
||||||
|
echo "Error: Neither mongo nor mongosh shell found. Please install MongoDB shell."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# MongoDB Java driver won't run authentication twice on the same DB instance,
|
# MongoDB Java driver won't run authentication twice on the same DB instance,
|
||||||
# so we need to use multiple DBs.
|
# so we need to use multiple DBs.
|
||||||
mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test
|
$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test
|
||||||
mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2
|
$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2
|
||||||
mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3
|
$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3
|
||||||
mongo --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4
|
$MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4
|
||||||
|
|
@ -1,8 +1,18 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Check which MongoDB shell is available in the container
|
||||||
|
if docker exec mongo_test which mongosh >/dev/null 2>&1; then
|
||||||
|
MONGO_SHELL="mongosh"
|
||||||
|
elif docker exec mongo_test which mongo >/dev/null 2>&1; then
|
||||||
|
MONGO_SHELL="mongo"
|
||||||
|
else
|
||||||
|
echo "Error: Neither mongo nor mongosh shell found in the container."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# MongoDB Java driver won't run authentication twice on the same DB instance,
|
# MongoDB Java driver won't run authentication twice on the same DB instance,
|
||||||
# so we need to use multiple DBs.
|
# so we need to use multiple DBs.
|
||||||
docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test
|
docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test
|
||||||
docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2
|
docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test2
|
||||||
docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3
|
docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test3
|
||||||
docker exec mongo_test mongosh --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4
|
docker exec mongo_test $MONGO_SHELL --eval 'db.createUser({"user": "clojurewerkz/monger", "pwd": "monger", roles: ["dbAdmin"], mechanisms: ["SCRAM-SHA-1"], passwordDigestor: "client"})' monger-test4
|
||||||
Loading…
Reference in a new issue