You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB or perform administrative operation.
This tutorial provides an introduction to writing JavaScript that uses the mongo shell to access MongoDB.
Opening New Connections
From the mongo shell or from a JavaScript file, you can instantiate database connections using the Mongo() constructor:
new Mongo()
new Mongo(