Info
The mongo shell connects to the default port when the connection string is incorrect and it prints a misleading message to the user leading them to believe they have connected correctly.
v3.0.14
mongo port=27018
MongoDB shell version: 3.0.14
connecting to: port=27018
v3.2.10
mongo port=27018
MongoDB shell version: 3.2.10
connecting to: port=27018
v3.4.0-rc3
mongo port=27018
MongoDB shell version v3.4.0-rc3
connecting to: mongodb://127.0.0.1:27017/port=27018
The latest version is probably the least likely to be confusing but perhaps a failure to connect would be more educational to the user.
Top User Comments
brooke.miller commented on Fri, 3 Dec 2021 18:47:45 +0000:
We've deprecated the mongo shell in favor of the new mongosh. Unfortunately, we aren't able to pursue improvements to the deprecated shell except in extreme cases, such as critical security fixes. Please start making use of mongosh and let us know if it works for you in this case.
matt.cotter commented on Tue, 6 Dec 2016 20:21:26 +0000:
For future reference, the solution here is to backport the work done to fix up the URI before printing it out to the v3.2 branch.
vick.mena commented on Mon, 28 Nov 2016 20:48:29 +0000:
matt.cotter Fair point. Perhaps just cleanup the non URI "connecting to: ..." messages to help the user avoid confusion much like the cleaner URI message (e.g. "hostname:port/db")
matt.cotter commented on Mon, 28 Nov 2016 19:20:15 +0000:
This is looks weird, but that's a valid database name.
Ex:
> use port=27018
switched to db port=27018
> db.test.insert({foo: 'bar'})
WriteResult({ "nInserted" : 1 })
then
$ mongo port=27018
MongoDB shell version v3.4.0-rc3
connecting to: mongodb://127.0.0.1:27017/port=27018
MongoDB server version: 3.4.0-rc3
> db.test.find()
{ "_id" : ObjectId("583c82f5e4a1d2efae9ddc5b"), "foo" : "bar" }
I think that the URI might make it clear what's happening. I agree that this is weird, but in my opinion there isn't anything to fix.
Steps to Reproduce
mongod --dbpath . --logpath mongod.log --fork
mongo port=27018