I am trying to create mongo users using javascript as part of an installation script.
I would like to know how to validate the return statement of the previous command before proceeding with the next.
For example in the following script,
var db = db.getSiblingDB("admin");
var status = db.createUser({user: "root",
pwd: "root",
roles: [
{ role: "root", db: "admin" }
]
});
I need to verify if db.createUser succeeded before running further commands.
Is it possible? When I tried to print status, console threw undefined type error.
Thanks in advance.