How does the shell create mongodb users

  mongodb, question

mongo test –eval db.createUser({user:”rwuser”, pwd:”titan7vc65x”, roles:[{role:”readWrite”, db:”test”}]})

This command can’t be used either. I need to create mongodb users in shell scripts. I can’t find any information online.

You are right to create statements. What you are looking for is not in mongo’s data. What you need to know is the usage of linux shell, and the escape of spaces or quotation marks.

mongo test --eval "db.createUser({user:\"rwuser\", pwd:\"titan7vc65x\", roles:[{role:\"readWrite\", db:\"test\"}]})"