0

I am trying to connect to my mongo data base and perform some commands on it such as:

#!/bin/bash

mongo myMongoDbip:27017/admin -u username -p pwd

mongo --shell --eval  "use neura_staging"

i can connect to the data base but all my other commands are not working such as using specific db.

can you elaborate some info about it?

thanks!

2
  • What exactly is the resulting output of your script? Commented Aug 9, 2015 at 14:40
  • I am connecting to the database but I notice that the command was not executed... I mean for using the other data base. Commented Aug 9, 2015 at 14:41

1 Answer 1

2

You should have something like this

#!/bin/bash

USER=username
PW=secret
AUTHDB=admin
LOGINDATA="-u $USER -p $PW --authenticationDatabase $AUTHDB"
HOST=hostname.example.com

mongo $HOST:27017 $LOGINDATA --shell --eval ’use neura_staging’

The reason why your second call to mongo does not work as expected is the this call opens a new (and since you did not provide any login data unauthenticated) connection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.