mongodb-memory-server: MongoDB Memory Sever // Unable to Startup and/or Connect

Versions

  • NodeJS: v17.5.0
  • mongodb-memory-server-*: 8.8.0
  • mongodb(the binary version): 5.8.0
  • mongodb(the js package): 2.0.19
  • system: MacOS

package: mongo-memory-server

from package.json:

  "config": {
    "mongodbMemoryServer": {
      "debug": "1"
    }
  },

What is your question?

Hey all. I do not know if this is a bug or not or something else I am doing wrong, but no matter what I do to “start” the MonogMemoryServer it never in the output shows that the “process” has started. I tried every possible varation that I can think of and I ran out of ideas.

I am using this for local development along with unit testing, and not just for unit testing. This would also run “in memory” on my development instance.

Trace

Here are the error messages:

[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node --trace-warnings src`
Debugger listening on ws://127.0.0.1:50295/c43d8872-575a-4a7d-be77-f2898cfaff3a
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
  MongoMS:ResolveConfig Debug Mode Enabled, through package.json +0ms
  MongoMS:MongoMemoryServer create: Called .create() method +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: start: Called .start() method +1ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Called MongoMemoryServer._startUpInstance() method +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: getStartOptions: forceSamePort: false +0ms
  MongoMS:MongoMemoryServer Mongo[unknown]: _startUpInstance: Creating new MongoDB instance with options: {
  instance: {
    port: 50311,
    dbName: '',
    ip: '0.0.0.0',
    storageEngine: 'wiredTiger',
    replSet: undefined,
    dbPath: '/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--17310-EG5By9TnK4Zd',
    tmpDir: {
      name: '/var/folders/cs/wq9ybm2956x6vjjl2rhk_9jr0000gn/T/mongo-mem--17310-EG5By9TnK4Zd',
      removeCallback: [Function: _cleanupCallback]
    },
    keyfileLocation: undefined,
    args: [ '--enableMajorityReadConcern=false' ],
    auth: false
  },
  binary: undefined,
  spawn: undefined
} +22ms
  MongoMS:MongoInstance create: Called .create() method +0ms
  MongoMS:MongoInstance Mongo[50311]: start +0ms
  MongoMS:MongoBinary getPath +0ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: ''
}  +0ms
  MongoMS:DryMongoBinary generateDownloadPath: no existing binary for version "5.0.8" was found +7ms
  MongoMS:DryMongoBinary generateDownloadPath: using global (preferGlobal) "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +0ms
  MongoMS:MongoBinary getPath: MongoBinary options: {
  "version": "5.0.8",
  "downloadDir": "/Users/me/.cache/mongodb-binaries",
  "os": {
    "os": "darwin"
  },
  "platform": "darwin",
  "arch": "x64",
  "systemBinary": "",
  "checkMD5": false
} +11ms
  MongoMS:DryMongoBinary locateBinary: Trying to locate Binary for version "5.0.8" +1ms
  MongoMS:DryMongoBinary generateOptions +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '/Users/me/.cache/mongodb-binaries',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generatePaths: resolveConfigValue is not empty +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8'
}  +0ms
[16:00:42 UTC] DEBUG: Processing Plugins...
[16:00:42 UTC] DEBUG: Processing Routes...
  MongoMS:DryMongoBinary generateDownloadPath: no existing binary for version "5.0.8" was found +400ms
  MongoMS:DryMongoBinary generateDownloadPath: using resolveConfig (DOWNLOAD_DIR) "/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8" +0ms
  MongoMS:DryMongoBinary locateBinary: running generateDownloadPath +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Generating Download Path, preferGlobal: "true" +0ms
  MongoMS:DryMongoBinary generatePaths {
  version: '5.0.8',
  downloadDir: '/Users/me/.cache/mongodb-binaries',
  os: { os: 'darwin' },
  platform: 'darwin',
  arch: 'x64',
  systemBinary: ''
} +0ms
  MongoMS:DryMongoBinary getBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +1ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generatePaths: resolveConfigValue is not empty +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary combineBinaryName +0ms
  MongoMS:DryMongoBinary generateDownloadPath: Paths: {
  legacyHomeCache: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8',
  modulesCache: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/node_modules/.cache/mongodb-memory-server/mongod-x64-darwin-5.0.8',
  relative: '/Users/me/Documents/MYREPO/GIT.nosync/app-name/mongodb-binaries/mongod-x64-darwin-5.0.8',
  resolveConfig: '/Users/me/.cache/mongodb-binaries/mongod-x64-darwin-5.0.8'
}  +0ms

I am on MacOSX system and updated to the latest code. I tried everything from different ports to the database name. Below is the javascript code that is excuting the start process.

Code Sample

const MongoClient = require('mongodb').MongoClient
const { MongoMemoryServer } = require('mongodb-memory-server')

// removed irrlevent code

class MongoDatabase extends DatabaseServices {

// removed irrlevent code

  async connectDatabase () {
    let mongoDbUri

    if (this.databaseInfo.localMemory) {

      let _mongo
      do {
        _mongo = await MongoMemoryServer.create({
          instance: {
            ip: '0.0.0.0',
            storageEngine: 'wiredTiger',  // I did this as a test, removed, it still didn't work
            args: ['--enableMajorityReadConcern=false'] // same here, but it didn't make a difference.
          }
        })
      } while(_mongo.getUri() === null)


      // set settings
      const _mongoUri = _mongo.getUri().replace(/\//gi, '').split(':') // NOTE: I never am able to connect and get the getUri method.
      this.databaseInfo.host = _mongoUri[1]
      this.databaseInfo.port = _mongoUri[2]

      mongoDbUri = 'mongodb://' + this.databaseInfo.host + ':' + this.databaseInfo.port
    }

  }
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 24

Most upvoted comments

closing because issue is stale and has gone slightly off-topic, if this issue should be encountered again feel free to post here (as long as the used mongodb-memory-server version is below 9.0)

ubuntu 22.04 (jammy) moved from openssl 1.1.1f-1ubuntu2.16 to openssl 3.0.2-0ubuntu1.7 . While the mongodb downloads page doesnt have a mongodb binary for jammy, their apt repo does have a version specifically for jammy that doesnt need openssl 1.1.1f, located at https://repo.mongodb.org/apt/ubuntu/dists/jammy/mongodb-org/6.0/multiverse/binary-amd64. So, for mongodb-memory-server to work on jammy, we’ll need to extract the binary from the .deb package.

I figured this out by comparingdpkg -l | grep " openssl " with the circleci nodejs images: docker run -it cimg/node:16.17.0 vs docker run -it cimg/node:16.18.1 (both docker images are based on ubuntu jammy, just at different moments in time), and ldd ~/.cache/mongodb-memory-server/mongod-x64-ubuntu-6.0.3 vs running ldd on the binary extracted from the above deb

Here’s a pastebin of the debug logs if that can be of any help: https://pastebin.com/muSaEavD I will dig them more thoroughly and edit this message if needed

your issue according to the logs is:

/home/eric-burel/.cache/mongodb-binaries/mongod-x64-ubuntu-5.0.8: /lib/x86_64-linux-gnu/libssl.so.1.1: version OPENSSL_1_1_1’ not found (required by /home/eric-burel/.cache/mongodb-binaries/mongod-x64-ubuntu-5.0.8)`

this means you are missing a OPENSSL library