I'm trying to create an npm
command that drops a database from my mongo instance.
When I paste this line of code directly into my shell, it works, and gives the output below:
> echo 'db.dropDatabase()' | mongo musicappdb
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017/musicappdb
MongoDB server version: 3.4.10
{ "ok" : 1 }
bye
However when I run it from my npm script, which is defined like this
scripts: {
...
"drop-db": "echo 'db.dropDatabase()' | mongo musicappdb",
...
},
I get
> echo "db.dropDatabase()" | mongo musicappdb
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017/musicappdb
MongoDB server version: 3.4.10
db.dropDatabase()
bye
And the database is NOT getting dropped.
Why is the command not behaving properly when I issue through npm?