./mongo localhost:27017/mydb myjsfile.js
Explanation:
This operation executes the myjsfile.js
script in a mongo
shell that connects to the mydb
database on the mongod
instance accessible via the localhost
interface on port 27017
. localhost:27017
is not mandatory as this is the default port mongodb
uses.
Also, you can run a .js
file from within mongo
console.
>load("myjsfile.js")