mongodb rs.status to list status of the node



  • the moment I use sed to replace node and port the quotes are removed and hence syntax error. Is there a different solution to this syntax error.

    NODE=abcd
    PORT=1234
    mongo_cmd="mongo admin -u $USER  -p $PASWD --host $NODE --port $PORT --quiet --eval 'rs.status().members.filter( x => x.name == "NODE:PORT" ).shift().stateStr)' "
    mongo_cmd=$(echo $mongo_cmd | sed -e "s/NODE/$NODE/" -e "s/PORT/$PORT/")
    echo $mongo_cmd
    

    mongo admin -u -p --host abcd --port 1234 --quiet --eval 'rs.status().members.filter( x => x.name == abcd:1234 ).shift().stateStr)'

    2022-03-09T23:45:45.300-0800 E QUERY [main] SyntaxError: missing ) after argument list @(shell eval):1:73



  • Maybe like this:

    NODE=abcd
    PORT=1234
    cmd="rs.status().members.filter( x => x.name == '$NODE:$PORT' ).shift().stateStr)"
    mongo_cmd="mongo admin -u '$USER'  -p '$PASWD' --host $NODE --port $PORT --quiet --eval "$cmd"
    

    or

    mongo_cmd="mongo 'mongodb://$USER:$PASWD@$NODE:$PORT/?authSource=admin' --quiet --eval "$cmd"
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2