Open jmbldwn opened 3 years ago
same issue
FYI, I was able to work around this problem, though I can't say for sure what exactly fixes this. Hopefully this will help others running into this.
Here's the code I use to establish the replica set and subsequently shut it down:
setupModelTest() {
const { MongoMemoryReplSet } = require('mongodb-memory-server'); // use this if mongo not on host
// const { MongoMemoryReplSet } = require('mongodb-memory-server-core');
let replSet;
let connection;
beforeAll(async () => {
replSet = await MongoMemoryReplSet.create({
replSet: { storageEngine: 'wiredTiger' },
});
await replSet.waitUntilRunning();
const uri = await replSet.getUri();
connection = await mongoose.connect(uri, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
poolSize: 100
});
});
afterAll(async () => {
// shut down all change streams that may be open (.stopWatch() is implemented in every model)
await require('.../models/xxx').stopWatch();
await require('.../models/yyy').stopWatch();
await connection.disconnect();
await replSet.stop();
});
},
FYI, I was able to work around this problem, though I can't say for sure what exactly fixes this. Hopefully this will help others running into this.
* I switched to using WiredTiger as the storage engine for mongodb-memory-server. * I modified my code that uses mongodb change streams to support shutting them down (for testing purposes) * I am using v7.0.0-beta38 of mongodb-memory-server
Here's the code I use to establish the replica set and subsequently shut it down:
setupModelTest() { const { MongoMemoryReplSet } = require('mongodb-memory-server'); // use this if mongo not on host // const { MongoMemoryReplSet } = require('mongodb-memory-server-core'); let replSet; let connection; beforeAll(async () => { replSet = await MongoMemoryReplSet.create({ replSet: { storageEngine: 'wiredTiger' }, }); await replSet.waitUntilRunning(); const uri = await replSet.getUri(); connection = await mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true, useFindAndModify: false, useUnifiedTopology: true, poolSize: 100 }); }); afterAll(async () => { // shut down all change streams that may be open (.stopWatch() is implemented in every model) await require('.../models/xxx').stopWatch(); await require('.../models/yyy').stopWatch(); await connection.disconnect(); await replSet.stop(); }); },
Thanks , I will try .
If I subscribe to a change stream, using mongoose's
watch
method, I encounter the following exception.Is there a way to configure the mongo memory server to support this?