How to pass argument to Mongo Script

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

    I solved this problem, by using the javascript bundler parcel: https://parceljs.org/

    With this, one can use node environment variables in a script like:

    var collection = process.env.COLLECTION;
    

    when building with parcel, the env var gets inlined:

    parcel build ./src/index.js --no-source-maps
    

    The only downside is, that you have to rebuild the script every time you want to change the env vars. But since parcel is really fast, this is not really a problem imho.

提交回复
热议问题