Running a shell script
The shell scripts you create and plan to run using the mongo shell must follow standard JavaScript (https://developer.mozilla.org/en-US/docs/Web/JavaScript) syntax. You are free to use any of the built-in mongo shell methods (https://docs.mongodb.com/manual/reference/method/#mongo-shell-methods), however the mongo command helpers (https://docs.mongodb.com/manual/reference/mongo-shell/#command-helpers) are not available for use, as they are not valid JavaScript functions.
Here is an example of a shell script that inserts three customers, and after each insert, unsets the password field. Note that you cannot issue the command use <database> to select the database, as you would inside the shell. As this is a script, you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access