[SERVER-6233] Support MongoDB URIs as mongo shell argument Created: 28/Jun/12  Updated: 24/Nov/17  Resolved: 14/Oct/15

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.7.4
Fix Version/s: 3.2.0-rc0

Type: Bug Priority: Trivial - P5
Reporter: Richard Kreuter (Inactive) Assignee: Jonathan Reams
Resolution: Done Votes: 5
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-9033 Support MongoDB URIs as mongo shell a... Closed
Duplicate
is duplicated by SERVER-15739 Make error message when passing a "mo... Closed
is duplicated by SERVER-3300 MongoURI support for connecting to a ... Closed
Related
related to SERVER-28560 Support specifying multiple mongos pr... Closed
related to SERVER-32083 mongo --help should mention URI feature Closed
is related to SERVER-22383 mongo shell should permit mongodb:// ... Closed
is related to SERVER-15739 Make error message when passing a "mo... Closed
is related to SERVER-22382 mongo shell should accept mongodb:// ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Build A (10/09/15), Build B (10/30/15)
Participants:

 Description   

It would be more consistent with the drivers if the shell supported URIs, in addition to --host replSetName/seed-list format it already supports.
E.g.

mongo mongodb://test:test@127.0.0.1:27017/test

Original description was:
The shell appears not to be able to take mongodb:// urls as elements of argv.
The shell appears not to be able to connect to a replica set specified as <rsname>/host1[:port1][,host2:[:port2]...] as elements of argv. Either of these would be nice, but if we do just one, the first is better than the second, as the double-slashes in the URL are already an error for the shell's idiosyncratic connection syntax.



 Comments   
Comment by Githook User [ 14/Oct/15 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-6233 Fix compiling on clang
Branch: master
https://github.com/mongodb/mongo/commit/3c706c7fcabbb267a29c482b1c016e838ce82588

Comment by Githook User [ 14/Oct/15 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-6233 Add URI parsing to mongo shell
Branch: master
https://github.com/mongodb/mongo/commit/53c52c43a99d14a9e6c47bcc1ca1e7a2fa044ef0

Comment by Roman Dutchak [ 20/Aug/15 ]

ramon.fernandez Good, I will try to do in the near future! Thank you!

Comment by Ramon Fernandez Marina [ 19/Aug/15 ]

dutchakdev, this is to let you know that we'll be taking a closer look at this ticket and your pull request in the next sprint in a couple of weeks. Adding a test to check that the functionality you added works as expected will go a long way towards making quick progress on this ticket.

Thanks,
Ramón.

Comment by Ramon Fernandez Marina [ 05/Aug/15 ]

Thanks for the updated pull request dutchakdev; running it through our internal testing now. Please note that it's desirable to include tests in pull requests, to make sure functionality works as expected and is not broken by subsequent changes.

Comment by Roman Dutchak [ 15/Jul/15 ]

thomasr, Fixed in https://github.com/mongodb/mongo/pull/995
Working with:

+/* https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/client/dbclient.cpp#L82-L97 */
+namespace {
+    const char kMongoDBURL[] =
+        // scheme: non-capturing
+        "mongodb://"
+
+        // credentials: two inner captures for user and password
+        "(?:([^:]+)(?::([^@]+))?@)?"
+
+        // servers: grabs all host:port or UNIX socket names
+        "((?:(?:[^\\/]+|/.+.sock?),?)+)"
+
+        // database: matches anything but the chars that cannot
+        // be part of a MongoDB database name.
+        "(?:/([^/\\.\\ \"*<>:\\|\\?]*))?"
+
+        // options
+        "(?:\\?(?:(.+=.+)&?)+)*";
+
+} // namespace
+

Comment by Asya Kamsky [ 15/Jun/15 ]

shouldn't this ticket have been made dup of SERVER-3300 since this part is partially incorrect and that one has more discussion?

Comment by Thomas Rueckstiess [ 27/Aug/14 ]

This is still an issue in 2.6.4

mongo mongodb://localhost:27017/foo
MongoDB shell version: 2.6.4
connecting to: mongodb://localhost:27017/foo
2014-08-27T11:19:14.349-0400 Assertion failure _setName.size() src/mongo/client/dbclientinterface.h 219
2014-08-27T11:19:14.351-0400 0x10018d41b 0x10014b352 0x10013b002 0x100042517 0x10003abf0 0x100119cbf 0x100103318 0x100290760 0xad5b3a06362
 0   mongo                               0x000000010018d41b _ZN5mongo15printStackTraceERSo + 43
 1   mongo                               0x000000010014b352 _ZN5mongo10logContextEPKc + 114
 2   mongo                               0x000000010013b002 _ZN5mongo12verifyFailedEPKcS1_j + 274
 3   mongo                               0x0000000100042517 _ZN5mongo16ConnectionStringC2ENS0_14ConnectionTypeERKSsS3_ + 239
 4   mongo                               0x000000010003abf0 _ZN5mongo16ConnectionString5parseERKSsRSs + 124
 5   mongo                               0x0000000100119cbf _ZN5mongo17mongoConsExternalEPNS_7V8ScopeERKN2v89ArgumentsE + 319
 6   mongo                               0x0000000100103318 _ZN5mongo7V8Scope10v8CallbackERKN2v89ArgumentsE + 90
 7   mongo                               0x0000000100290760 _ZN2v88internalL30Builtin_HandleApiCallConstructENS0_12_GLOBAL__N_116BuiltinArgumentsILNS0_21BuiltinExtraArgumentsE1EEEPNS0_7IsolateE + 560
 8   ???                                 0x00000ad5b3a06362 0x0 + 11912957944674
2014-08-27T11:19:14.353-0400 Error: assertion src/mongo/client/dbclientinterface.h:219 at src/mongo/shell/mongo.js:148

Same for 2.7.4.

Generated at Thu Feb 08 03:11:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.