How to pass argument to Mongo Script

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

    I used a shell script to pipe a mongo command to mongo. In the mongo command I used an arg I passed to the shell script (i.e. i used $1):

    #!/bin/sh
    
    objId=$1
    EVAL="db.account.find({\"_id\" : \"$objId\"})"
    echo $EVAL | mongo localhost:27718/balance_mgmt --quiet
    

提交回复
热议问题