Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoParseError: URI malformed, cannot be parsed #141

Closed
sam-araiza opened this issue Feb 26, 2019 · 21 comments
Closed

MongoParseError: URI malformed, cannot be parsed #141

sam-araiza opened this issue Feb 26, 2019 · 21 comments
Labels
bug released on @beta released Pull Request released | Issue is fixed
Milestone

Comments

@sam-araiza
Copy link

sam-araiza commented Feb 26, 2019

async function test() {
  const mms = new MongoMemoryServer()
  const mongoUri = await mms.getConnectionString()

  return MongoClient
    .connect(mongoUri, { useNewUrlParser: true })
    .then(async (client) => {
      const testDb = client.db(await mms.getDbName())
      console.log('Successful Test DB Connection to ', mongoUri)

      testDb.close = () => {
        if (client) client.close()
        if (mms) mms.stop()
      }

      return testDb
    })
    .catch(err => console.error(err))
}

getConnectionString seems to be returning an unsupported URI format. It still connects successfully, but seeing this in the terminal over and over is annoying.

"mongodb-memory-server": "^3.1.1",
"mongodb": "^3.1.11",
@nodkz
Copy link
Owner

nodkz commented Feb 26, 2019

What was exactly generated for connection string? And what is your operation system?

Thanks.

@hasezoey hasezoey added bug stale This Issue is outdated and will likely be closed if no further comments are given labels Sep 7, 2020
@hasezoey
Copy link
Collaborator

closing because stale for over 3 months

@me-nkr
Copy link

me-nkr commented Jun 15, 2021

Got the same error, mongod.getUri() returned "mongodb://127.0.0.1:38633/a467d6cf-da1b-4050-a833-1c74963e568f"

and got (node:5241) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed, cannot be parsed

@me-nkr
Copy link

me-nkr commented Jun 15, 2021

Also it seems like process.env.MONGO_URL is returning undefined

@hasezoey
Copy link
Collaborator

Also it seems like process.env.MONGO_URL is returning undefined

this is never even defined by this package

@hasezoey hasezoey removed Needs More Information stale This Issue is outdated and will likely be closed if no further comments are given labels Jun 15, 2021
@hasezoey hasezoey reopened this Jun 15, 2021
@hasezoey
Copy link
Collaborator

hasezoey commented Jun 15, 2021

changing target of the issue:

  • it seems like - is not allowed in database names (or at least it cannot be parsed?)
  • change documentation & code to show that its the auth db not default use database

Note: its for 7.x, because it is an kinda breaking change

@hasezoey hasezoey added this to the 7.0 milestone Jun 15, 2021
@hasezoey
Copy link
Collaborator

btw, the workaround for now is to add an parameter to getUri calls to define an custom database (example: server.getUri("authDB"))

@me-nkr
Copy link

me-nkr commented Jun 15, 2021

this is never even defined by this package

sorry my bad, I thought I'm using @shelf/jest-mongodb

@me-nkr
Copy link

me-nkr commented Jun 15, 2021

btw, the workaround for now is to add an parameter to getUri calls to define an custom database (example: server.getUri("authDB"))

this worked, i used client = new MongoClient(mongo.getUri('testDB')) and it pretty much works fine

@me-nkr
Copy link

me-nkr commented Jun 15, 2021

btw I have a question. Is there any issue with using mongodb-memory-server with jest ? cause I'm getting TypeError: Cannot read property 'JSON' of null error, even when connecting to real mongo servers. ( I know it's off topic, but any help is much appreciated)

@hasezoey
Copy link
Collaborator

may depend on how you use jest, but i never had that problem

@me-nkr
Copy link

me-nkr commented Jun 15, 2021

I'm using jest without even custom configurations

@sam-araiza
Copy link
Author

@hasezoey @me-nkr Thank you both! The workaround is noted. Can technically still cause an issue, so I'll leave it up to you guys to keep open or close. Thanks again!

@hasezoey
Copy link
Collaborator

hasezoey commented Jun 17, 2021

7b986e1 & 840be19 should fix this (7.0.0-beta.46)

where was this used when this problem came up, mongodb driver or mongoose or both? @me-nkr @sam-araiza
asking because it seems the URI format slightly differs between these two (with mongodb /db mean authentication database, and mongoose means default database for the connection & models)

hasezoey added a commit that referenced this issue Jun 17, 2021
BREAKING CHANGE:
`getUri`'s parameter got changed to what the actual definition is, and uses "admin" by default

fixes #141
@github-actions
Copy link

🎉 This issue has been resolved in version 7.0.0-beta.45 🎉

The release is available on:

Your semantic-release bot 📦🚀

hasezoey added a commit that referenced this issue Jun 17, 2021
BREAKING CHANGE:
`getUri`'s parameter got changed to use  ""(empty) by default

fixes #141
@github-actions
Copy link

🎉 This issue has been resolved in version 7.0.0-beta.46 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sam-araiza
Copy link
Author

7b986e1 & 840be19 should fix this (7.0.0-beta.46)

where was this used when this problem came up, mongodb driver or mongoose or both? @me-nkr @sam-araiza
asking because it seems the URI format slightly differs between these two (with mongodb /db mean authentication database, and mongoose means default database for the connection & models)

mongodb driver for me. our team is not using mongoose.

@me-nkr
Copy link

me-nkr commented Jun 22, 2021

7b986e1 & 840be19 should fix this (7.0.0-beta.46)

where was this used when this problem came up, mongodb driver or mongoose or both? @me-nkr @sam-araiza
asking because it seems the URI format slightly differs between these two (with mongodb /db mean authentication database, and mongoose means default database for the connection & models)

mongo driver for me too

@hasezoey
Copy link
Collaborator

closing because fixed in 7.0.0-beta.46

@github-actions
Copy link

github-actions bot commented Jul 1, 2021

🎉 This issue has been resolved in version 7.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Pull Request released | Issue is fixed label Jul 1, 2021
@aghosh0605
Copy link

Most of the time it happens that I use nodeJS and name my env file as .env.local (same as NextJS). So process.env can't find the Mongo URL and takes it as undefined. So be sure to name the env file as per libraries and frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug released on @beta released Pull Request released | Issue is fixed
Projects
None yet
Development

No branches or pull requests

5 participants