[SERVER-57929] Inconsistent handling of mongodb:// URIs Created: 17/Jun/21 Updated: 27/Oct/23 Resolved: 28/Jun/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.0.25 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Tais P. Hansen | Assignee: | Edwin Zhou |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
DescriptionAttempting to use the mongodb URI "mongodb://0.0.0.0:27017/db" works with mongodump/mongorestore but fails with mongo shell. When running mongo inside a docker-compose environment, I would typically run "docker-compose port mongodb 27017" to get the address and port which docker mapped the docker container port to on the local host. Ie. it could respond with "0.0.0.0:49156".
Example: MONGODB_URI="mongodb://$(docker-compose port mongodb 27017)/db" mongorestore --uri "$MONGODB_URI" --dir dump --drop mongo "$MONGODB_URI" database/transformMessages.js
The last step fails however, which the error message below: MongoDB shell version v4.0.25
And just to confirm a connection is possible: curl -sv http://0.0.0.0:49156/
Steps to Reproduce1. docker run --rm -it -p 27017 --name mongo -d mongo 2. MONGODB_URI="mongodb://$(docker port mongo 27017 | head -n1)/test" 3. mongo "$MONGODB_URI"
|
| Comments |
| Comment by Tais P. Hansen [ 29/Jun/21 ] |
|
Hi Edwin,
Mongo shell is the only tool I've encountered that cannot use 0.0.0.0. Both mysql, psql and cockroach are all able to connect to a server using 0.0.0.0 as the host name.
RFC 5735 states:
I find it odd that you would accept inconsistent behaviour between mongo's own tools. This should be changed from a bug to a feature request then.
|
| Comment by Edwin Zhou [ 28/Jun/21 ] |
|
The IP address 0.0.0.0 is typically reserved for something unspecified. In the mongo shell, we throw an error when the host address is "0.0.0.0". As you can see from the output from the curl command, the address 0.0.0.0 is resolving to 127.0.0.1, which is the localhost address. You may find success replacing "0.0.0.0" with "127.0.0.1". Best, |
| Comment by Tim Fogarty [ 22/Jun/21 ] |
|
Hi tais.hansen@gmail.com, sorry to hear about this. It sounds like you're specifically having trouble with the behavior of the mongo shell. So I'm going to move this ticket to the Server Jira project (which is where we track issues with the mono shell) so somebody can take a closer look. |