When I run the following script:
mongo -u root myinitscript.js
And myinitscript.js has the following code:
use somedbname
db.createUser({
user: 'someuser',
pwd: 'somepass',
roles: [{
role: 'dbOwner',
db: 'somedbname'
}]
});
Produces the following error:
MongoDB shell version v4.4.0
Enter password:
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("352e2ff4-3c4b-4e4c-b898-b67450c13627") }
MongoDB server version: 4.4.0
uncaught exception: SyntaxError: unexpected token: identifier :
@mongodb_init.js:1:4
failed to load: mongodb_init.js
exiting with code -3
When I remove use somedbname from the script - it works, but does NOT create the database, which is my primary goal. Running use somedbname under mongo shell works just fine, but is NOT an automation. Any hints on how to solve this?