typegoose/mongodb-memory-server

Consider supporting mongod option `--logpath`

hasezoey opened this issue · 1 comments

Consider supporting mongod option --logpath by either:

  • blindly assuming things
  • watch the file (if possible)
  • dont support --logpath and just add a option to dump the stdout to a file

watching a file would entail to either have another dependency or a custom made tail (because nodejs does not directly provide a tail -f like functionality)

this should make it easier to collect logs separate from MMS (and maybe anything else the option activates) for mongodb bug reports, like https://jira.mongodb.org/browse/SERVER-81018

Thank you for creating this. That's my ticket and currently trying to find out how to collect those logs.

I managed to get the logfiles of the instances by applying a few patches to the MMS files.
For future reference what I did:

diff --git a/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts b/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
index 31400313..6f2689c0 100644
--- a/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
+++ b/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts
@@ -767,6 +767,7 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced
               log('_waitForPrimary: found instance being already primary');
               res();
             }
+            res()
           })
       ),
       new Promise((_res, rej) => {
diff --git a/packages/mongodb-memory-server-core/src/util/MongoInstance.ts b/packages/mongodb-memory-server-core/src/util/MongoInstance.ts
index bfb954b8..dc0d4242 100644
--- a/packages/mongodb-memory-server-core/src/util/MongoInstance.ts
+++ b/packages/mongodb-memory-server-core/src/util/MongoInstance.ts
@@ -514,7 +514,9 @@ export class MongoInstance extends EventEmitter implements ManagerBase {

     childProcess.unref();

+    this.emit(MongoInstanceEvents.instanceReady)
     this.emit(MongoInstanceEvents.instanceLaunched);
+    this.emit(MongoInstanceEvents.instancePrimary);

     return childProcess;
   }

Just make sure to await for a successful connection somewhere in your application code as MMS will return before the database is ready.