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 ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.