Skip to content

Commit

Permalink
feat(mongosh): Add mongosh command (#12)
Browse files Browse the repository at this point in the history
* feat(mongosh): Add mongosh command

* test(mongosh): Add test for mongosh tool
  • Loading branch information
julienloizelet authored Aug 8, 2023
1 parent 5bff99b commit 14acb12
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
11 changes: 11 additions & 0 deletions commands/mongo/mongosh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
#ddev-generated
# Remove the line above if you don't want this file to be overwritten when you run
# ddev get ddev/ddev-mongo
#
# This file comes from https://github.com/ddev/ddev-mongo
#
## Description: Run mongosh command
## Usage: mongosh <command>
## Example: "ddev mongosh "mongodb://mongo:27017"
mongosh "$@"
8 changes: 6 additions & 2 deletions docker-compose.mongo.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ddev-generated
version: '3.6'

# Remove the line above if you don't want this file to be overwritten when you run
# ddev get ddev/ddev-mongo
#
# This file comes from https://github.com/ddev/ddev-mongo
#
services:
mongo:
container_name: ddev-${DDEV_SITENAME}-mongo
Expand All @@ -11,6 +14,7 @@ services:
target: "/data/db"
volume:
nocopy: true
- ".:/mnt/ddev_config"
restart: "no"
expose:
- "27017"
Expand Down
1 change: 1 addition & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pre_install_actions:
# list of files and directories listed that are copied into project .ddev directory
project_files:
- commands/mongo/mongosh
- docker-compose.mongo.yaml
20 changes: 20 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ teardown() {
out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user")
[ "${out}" = "db" ]
(ddev exec php -i | grep mongodb.debug) || (echo "# php mongodb extension not found" >&3 || exit 1)
# Test mongosh
result=$(ddev mongosh "mongodb://db:db@mongo:27017/test?authSource=admin" --quiet --eval '"printjson(db.getUsers())"' --json | grep "ok" | sed 's/: 1/ /g' | sed 's/ //g' | tr ' \n' '#')
if [[ $result == "ok#" ]]
then
echo "# Mongosh OK" >&3
else
echo "# Mongosh KO"
echo "$result"
exit 1
fi
}

@test "install from release" {
Expand All @@ -41,4 +51,14 @@ teardown() {
out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user")
[ "${out}" = "db" ]
(ddev exec php -i | grep mongodb.debug) || (echo "# php mongodb extension not found" >&3 || exit 1)
# Test mongosh
result=$(ddev mongosh "mongodb://db:db@mongo:27017/test?authSource=admin" --quiet --eval '"printjson(db.getUsers())"' --json | grep "ok" | sed 's/: 1/ /g' | sed 's/ //g' | tr ' \n' '#')
if [[ $result == "ok#" ]]
then
echo "# Mongosh OK" >&3
else
echo "# Mongosh KO"
echo "$result"
exit 1
fi
}

0 comments on commit 14acb12

Please sign in to comment.