mongodb shell require a js function from another file

199 views Asked by At

I have two Mongodb shell scripts written in js. Both are sharing some code between them. Is it possible to extract that code to another file and to import it from there? And how?

I have been trying with require / import but that obviously not working, also tried with load() but no success.

I know it is using the SpiderMonkey js engine, but no idea if it is possible.

1

There are 1 answers

4
JJussi On

Yes! The solution is .mongorc.js file at your home directory.

Check documentation here!