How to pass argument to Mongo Script

前端 未结 6 1507
闹比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:25

    You can't do that, but you could put them in another script and load that first:

    // vars.js
    msg = "apples";
    

    and getSimilar.js was:

    print(msg);
    

    Then:

    $ mongo vars.js getSimilar.js
    MongoDB shell version: blah
    connecting to: test
    loading file: vars.js
    loading file: getSimilar.js
    apples
    

    Not quite as convenient, though.

提交回复
热议问题