How to pass argument to Mongo Script

前端 未结 6 1529
闹比i
闹比i 2020-12-12 19:41

I\'ve been using mongo and script files like this:

$ mongo getSimilar.js

I would like to pass an argument to the file:

$ mo         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 20:03

    Use --eval and use shell scripting to modify the command passed in.

    mongo --eval "print('apples');"

    Or make global variables (credit to Tad Marshall):

    $ cat addthem.js
    printjson( param1 + param2 );
    $ ./mongo --nodb --quiet --eval "var param1=7, param2=8" addthem.js
    15
    

提交回复
热议问题