Skip to content

Commit

Permalink
fix: adding replicaset info to mongosh connection command. Adding mon…
Browse files Browse the repository at this point in the history
…godb port variable (#145)

- Include the MongoDB port in the mongosh command (useful when running MongoDB in a different port)
- Include the replica set info in the mongosh command. It could be the case you aren't connected to a replica set primary but to a secondary one. If the replica set name is not specified, the mongosh command will fail since it is not possible to write to a secondary
  • Loading branch information
jfavellar90 authored Oct 16, 2024
1 parent 29e31dd commit 8855736
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drydock/templates/drydock/task/mongodb/init
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
echo "Initialising MongoDB..."
mongosh --host {{MONGODB_HOST }} {% if MONGODB_ROOT_USERNAME and MONGODB_ROOT_PASSWORD %} -u {{ MONGODB_ROOT_USERNAME }} -p {{ MONGODB_ROOT_PASSWORD }} {% endif %} admin <<EOF
mongosh --host {% if MONGODB_REPLICA_SET %}{{ MONGODB_REPLICA_SET }}/{% endif %}{{ MONGODB_HOST }} --port {{ MONGODB_PORT }} {% if MONGODB_ROOT_USERNAME and MONGODB_ROOT_PASSWORD %}-u {{ MONGODB_ROOT_USERNAME }} -p {{ MONGODB_ROOT_PASSWORD }}{% endif %} admin <<EOF
{% if MONGODB_USERNAME %}
if (db.getUser("{{ MONGODB_USERNAME }}") == null) {
db.createUser({
Expand Down

0 comments on commit 8855736

Please sign in to comment.