For standalone mongo setup (single node)
mongo -u <user> -p <password> mongodb://HOST_IP:27017/DB_NAME --eval 'MONGO_QUERY'
Example:
mongo mongodb://127.0.0.1:27017/test --eval 'db.collection.count()'
For clustered mongo setup (Replicaset with multiple nodes)
mongo -u <user> -p <password> mongodb://NODE_1_IP:27017,NODE_2_IP:27017,NODE_3_IP:27017/DB_NAME?replicaSet=RS_ID --eval 'MONGO_QUERY'
Example:
mongo mongodb://127.0.0.1:27017,127.0.0.2:27017,127.0.0.3:27017/test?replicaSet=rs0 --eval 'db.collection.count()'
PS: The user/pass in the above examples have been ignored but you need to add them if mongo has to auth.