mongodb-memory-server: restarting replset with already existing files fails with "already initialized"

Disclaimer: I know that not the intention of this library at first place and I probably shouldn’t abuse it this way.

Versions

  • NodeJS: 12.x
  • mongodb-memory-server-*: 6.3.1
  • mongodb: default that comes for arch
  • system: arch

package: mongo-memory-server

What is your question?

The issue i’m trying to solve is that within out company there are people accross all OSes which want to play around with our not yet released api which relies on a mongodb running on the system.

For our stuff to work we need a somehwat up-to-date version of mongodb with a replicaset, so we created a simple script which uses 'mongodb-memory-server to start a mongodb without the setup hassle and it works great 👍

One problem though is that in some cases we’d like to persist the test data trough system reboots and stuff like that 😅

So I was wondering if there is a way to start mongodb with previously persisted data similar to mongod --dbpath database --replSet rs? I saw there’s a:

instanceOpts: [
    {
      port: 27017,
      dbPath: "database",
    },
  ],

option to specify the path, but when reusing a path from a previous run I get the following error

(node:29641) UnhandledPromiseRejectionWarning: MongoError: already initialized
    at MessageStream.messageHandler (/home/lukass/Documents/sputnik/node_modules/mongodb/lib/cmap/connection.js:261:20)
    at MessageStream.emit (events.js:311:20)
    at processIncomingData (/home/lukass/Documents/sputnik/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/home/lukass/Documents/sputnik/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at doWrite (_stream_writable.js:441:12)
    at writeOrBuffer (_stream_writable.js:425:5)
    at MessageStream.Writable.write (_stream_writable.js:316:11)
    at Socket.ondata (_stream_readable.js:714:22)
    at Socket.emit (events.js:311:20)
    at addChunk (_stream_readable.js:294:12)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (2 by maintainers)

Most upvoted comments