[SERVER-22707] MongoDB shell's parsing of connection string uses incorrect regular expression Created: 17/Feb/16  Updated: 10/Apr/17  Resolved: 14/Jul/16

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.2.3
Fix Version/s: 3.2.13, 3.3.10

Type: Bug Priority: Major - P3
Reporter: Kaloian Manassiev Assignee: Matt Cotter
Resolution: Done Votes: 0
Labels: bkp
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by CXX-846 Connection string URI parsing is no c... Closed
Related
related to SERVER-22383 mongo shell should permit mongodb:// ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.2
Steps To Reproduce:

See the description.

Sprint: Platforms 17 (07/15/16)
Participants:

 Description   

The JS parsing of the mongodb connection string is incorrect:

> var mongoHost = 'mongodb://kaloianm-ubuntu:12345/?connectTimeoutMS=30000&socketTimeoutMS=30000';
 
> mongoHost
mongodb://kaloianm-ubuntu:12345/?connectTimeoutMS=30000&socketTimeoutMS=30000
 
> var mongo = new Mongo(mongoHost);
2016-02-17T16:17:10.121-0500 E QUERY    [thread1] Error: Unknown exception :
@(shell):1:17

The reason why it fails is that the regular expression used by the MongoURI parser treats the entire string as the hostname.



 Comments   
Comment by Githook User [ 10/Apr/17 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-22707 fix mongo uri parse

  • comma is not optional in comma separated host list
  • ".sock" domain sockets need the "."
  • even with no database, need a slash before options
  • no spamming question marks inside the options

(cherry picked from commit 40f774eafa4c0394cc75c936143ce6e185e5b1eb)
Branch: v3.2
https://github.com/mongodb/mongo/commit/f7ac0e8ed2aaeb64ddeefde00a446bc3444a1e29

Comment by Githook User [ 14/Jul/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-22707 fix mongo uri parse

Comment by Kaloian Manassiev [ 17/Feb/16 ]

For some reason, the order of the options matters:

This errors out:

var mongo = new Mongo('mongodb://kaloianm-ubuntu:12345/?connectTimeoutMS=30000&socketTimeoutMS=30000');

This succeeds:

var mongo = new Mongo('mongodb://kaloianm-ubuntu:12345/?socketTimeoutMS=30000&connectTimeoutMS=30000');

Comment by Kaloian Manassiev [ 17/Feb/16 ]

Single option does not work when you go through the MongoURI constructor either (new Mongo from JS). Regardless of whether it has database or not:

> var mongoHost = 'mongodb://kaloianm-ubuntu:12345/test?socketTimeoutMS=30000';
> var mongo = new Mongo(mongoHost);
2016-02-17T16:46:07.476-0500 E QUERY    [thread1] Error: Unknown exception :
@(shell):1:17

So I think this ticket is more generic than SERVER-22383.

Comment by Kevin Pulo [ 17/Feb/16 ]

Dupe of SERVER-22383? Or something else regarding parsing of multiple options?

This doesn't work for me whether via cmdline or Mongo constructor. Whereas a simpler uri works fine via the Mongo constructor.

$ /m/3.2.1/bin/mongo 'mongodb://genique:27017/?connectTimeoutMS=30000&socketTimeoutMS=30000'
FailedToParse std::exception
try '/m/3.2.1/bin/mongo --help' for more information
$ /m/3.2.1/bin/mongo 'mongodb://genique:27017/test?connectTimeoutMS=30000&socketTimeoutMS=30000'
FailedToParse std::exception
try '/m/3.2.1/bin/mongo --help' for more information
 
$ /m/3.2.1/bin/mongo 'mongodb://genique:27017/?connectTimeoutMS=30000'
MongoDB shell version: 3.2.1
connecting to: mongodb://genique:27017/?connectTimeoutMS=30000
2016-02-18T08:31:48.555+1100 E QUERY    [thread1] Error: Missing database name in connection string "mongodb://genique:27017/?connectTimeoutMS=30000" :
connect@src/mongo/shell/mongo.js:220:1
@(connect):1:6
 
exception: connect failed
$ /m/3.2.1/bin/mongo 'mongodb://genique:27017/test?connectTimeoutMS=30000'
MongoDB shell version: 3.2.1
connecting to: mongodb://genique:27017/test?connectTimeoutMS=30000
> var m = new Mongo("mongodb://genique:27017/?connectTimeoutMS=30000&socketTimeoutMS=30000")
2016-02-18T08:32:24.447+1100 E QUERY    [thread1] Error: std::exception :
@(shell):1:13
 
> var m = new Mongo("mongodb://genique:27017/test?connectTimeoutMS=30000&socketTimeoutMS=30000")
2016-02-18T08:32:27.911+1100 E QUERY    [thread1] Error: std::exception :
@(shell):1:13
 
> var m = new Mongo("mongodb://genique:27017/test?connectTimeoutMS=30000")
> m
connection to mongodb://genique:27017/test?connectTimeoutMS=30000
> m = new Mongo("mongodb://genique:27017/?connectTimeoutMS=30000")
connection to mongodb://genique:27017/?connectTimeoutMS=30000
> m = new Mongo("mongodb://genique:27017/?socketTimeoutMS=30000")
connection to mongodb://genique:27017/?socketTimeoutMS=30000
> m = new Mongo("mongodb://genique:27017/")
connection to mongodb://genique:27017/
> m = new Mongo("mongodb://genique:27017/test")
connection to mongodb://genique:27017/test

Generated at Thu Feb 08 04:01:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.