How to require scripts in the command shell Mongo Shell CLI

I would like to be able to import a library of common tools that I use to make working with MongoDB easier. However, I did not find it easy to import external scripts into the Mongo CLI. Ideally, this will work like Node.js require.

How do I get a job request in the Mongo CLI by default?

Or is there another way to solve the external dependencies of the library?

+5
source share
1 answer

There are several options for loading JavaScript into the shell mongo:

1) Save the javascript .mongorc.jsin your home directory.

2) JavaScript global mongorc.js (MongoDB 2.6+), .mongorc.js .

3) load('filename.js') ( mongorc.js).

4) JavaScript , system.js db.loadServerScripts().

JavaScript .

+9

All Articles