Based on the answer by Matt for the question asked here:
I tried the below script
use sample
db.testCollection.insert({"result":1})
However when I run as suggested, get an error as below and the record gets inserted in a collection of the default db and not in the 'sample' db as expected.
[tmp]# mongo < output.js
connecting to: mongodb://127.0.0.1:27017
2018-03-21T14:54:52.713+0530 E QUERY [thread1] SyntaxError: unterminated string literal @(shellhelp2):1:21
WriteResult({ "nInserted" : 1 })
bye
Kindly request for help.