mongodb-memory-server: MongoParseError: URI malformed, cannot be parsed

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",

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (1 by maintainers)

Commits related to this issue

Most upvoted comments

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

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