############################################################################## ## SETUP ############################################################################## ## Downloaded and built the MDB tools per README availabe here: https://github.com/mongodb/mongo-tools ~/.go/src/github.com/mongodb/mongo-tools(master) $ cd bin ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ls -al total 292960 drwxr-xr-x 10 andrew.feierabend staff 320 Jun 24 13:02 . drwxr-xr-x 38 andrew.feierabend staff 1216 Jun 24 12:52 .. -rwxr-xr-x 1 andrew.feierabend staff 15986132 Jun 24 13:01 bsondump -rwxr-xr-x 1 andrew.feierabend staff 19341388 Jun 24 13:02 mongodump -rwxr-xr-x 1 andrew.feierabend staff 19120972 Jun 24 13:02 mongoexport -rwxr-xr-x 1 andrew.feierabend staff 19103124 Jun 24 13:01 mongofiles -rwxr-xr-x 1 andrew.feierabend staff 19267380 Jun 24 13:02 mongoimport -rwxr-xr-x 1 andrew.feierabend staff 19595844 Jun 24 13:02 mongorestore -rwxr-xr-x 1 andrew.feierabend staff 18936980 Jun 24 13:01 mongostat -rwxr-xr-x 1 andrew.feierabend staff 18627396 Jun 24 13:02 mongotop ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ./mongodump --version mongodump version: 100.0.2-9-gb7227e1b git version: b7227e1b7aeaaa6283d53b32fc03968a46b19c2d Go version: go1.14.4 os: darwin arch: amd64 compiler: gc ############################################################################## ## TESTING: Using environment variables with the DBTOOLs ############################################################################## # Auth works as expected: ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ./mongodump "mongodb+srv://cluster1.k45tj.mongodb-dev.net/test?authSource=%24external&authMechanism=MONGODB-AWS" --username --password ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ # Mangling my password fails as expected: ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ./mongodump "mongodb+srv://cluster1.k45tj.mongodb-dev.net/test?authSource=%24external&authMechanism=MONGODB-AWS" --username --password fakefakefakefakefake 2020-06-24T14:54:07.558-0400 Failed: can't create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "MONGODB-AWS": (AuthenticationFailed) Authentication failed. # However, setting the standard AWS environment variables has no effect on DB Tool, tool still expects --username field to be present (example shown is bash): ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ export AWS_ACCESS_KEY_ID='' ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ export AWS_SECRET_ACCESS_KEY='' ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ env | grep AWS AWS_SECRET_ACCESS_KEY= AWS_ACCESS_KEY_ID= ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ./mongodump "mongodb+srv://cluster1.k45tj.mongodb-dev.net/test?authSource=%24external&authMechanism=MONGODB-AWS" 2020-06-24T15:02:05.430-0400 error parsing command line options: must set a username when using an SRV scheme 2020-06-24T15:02:05.430-0400 try 'mongodump --help' for more information ## Compare to shell behavior, which follows behavior as outlined in this doc example: https://docs.mongodb.com/master/reference/program/mongo/#connect-to-a-mongodb-atlas-cluster-using-aws-iam-credentials ## Second half of example covers setting these environment variables. The mongo shell automatically checks for them without further user action: ## the user need only set the two (or three, if also using a session token), and then omit username and password (and optionally session token) from the connecting string. ############################################################################## ## TESTING: Confusing error message with DNS lookup failure ############################################################################## # Confusing error message when DNS resolution fails: ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ./mongodump 'mongodb+srv://:@fakefakefake.mongodb-dev.net/testdb?authSource=$external&authMechanism=MONGODB-AWS' 2020-06-24T15:52:56.588-0400 error parsing command line options: error parsing positional arguments: provide only one MongoDB connection string. Connection strings must begin with mongodb:// or mongodb+srv:// schemes 2020-06-24T15:52:56.588-0400 try 'mongodump --help' for more information # Real hostname, otherwise identical command, works: ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ./mongodump 'mongodb+srv://:@cluster1.k45tj.mongodb-dev.net/testdb?authSource=$external&authMechanism=MONGODB-AWS' ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ # (no response because I didn't ask it to do anything, other than connect) # Compare to the error in mongo shell with DNS lookup failure (using mongo shell 4.4.0rc8): # Fed a bogus hostname: ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ~/Downloads/mongodb-macos-x86_64-4.4.0-rc8/bin/mongo 'mongodb+srv://:@fakefakefake.mongodb-dev.net/testdb?authSource=$external&authMechanism=MONGODB-AWS' DNSHostNotFound: Failed to look up service "_mongodb._tcp.cluster1.mongodb-dev.net": Undefined error: 0 try '/Users/andrew.feierabend/Downloads/mongodb-macos-x86_64-4.4.0-rc8/bin/mongo --help' for more information # Real hostname, otherwise identical command, works: ~/.go/src/github.com/mongodb/mongo-tools/bin(master) $ ~/Downloads/mongodb-macos-x86_64-4.4.0-rc8/bin/mongo 'mongodb+srv://:@cluster1.k45tj.mongodb-dev.net/testdb?authSource=$external&authMechanism=MONGODB-AWS' MongoDB shell version v4.4.0-rc8 connecting to: mongodb://cluster1-shard-00-00.k45tj.mongodb-dev.net:27017,cluster1-shard-00-01.k45tj.mongodb-dev.net:27017,cluster1-shard-00-02.k45tj.mongodb-dev.net:27017/testdb?authMechanism=MONGODB-AWS&authSource=%24external&compressors=disabled&gssapiServiceName=mongodb&replicaSet=atlas-pi2k3z-shard-0&ssl=true Implicit session: session { "id" : UUID("58018442-e2fa-44a8-a6f7-e1ea89fe747e") } MongoDB server version: 4.4.0-rc9 MongoDB Enterprise atlas-pi2k3z-shard-0:PRIMARY> ^C bye