I would like to know how to execute a JavaScript file in MongoDB.
This is the simple piece of code present in my JS file:
function loadNames() {
print("name");
}
From the command prompt I tried to execute the file like this
mongo test.js
but it shows the error:
unexpected identifier
Can anyone explain to me where I'm going wrong?
I usually run my test queries like this, and it works with your sample code too.
mongo < test.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With