Thanks for this awsome article. But since mongodb-memory-server version 7.0.0 we can't use anymore const mongoServer = new MongoMemoryServer(); but must use instead const mongo = await MongoMemoryServer.create(); . But I didn't succeed to adapt this to your code since that make me run await at file top level so I got the error "SyntaxError: await is only valid in async function". How would do you migrate your code to version 7?
Thank you for your comment!
I've updated article using the latest @7.2.1 version of mongodb-memory-server.
Basically, I define a new instance of "MongoMemoryServer" in the connect async function to automatically start server:
Thanks for this awsome article. But since mongodb-memory-server version 7.0.0 we can't use anymore
const mongoServer = new MongoMemoryServer();
but must use insteadconst mongo = await MongoMemoryServer.create();
. But I didn't succeed to adapt this to your code since that make me runawait
at file top level so I got the error "SyntaxError: await is only valid in async function". How would do you migrate your code to version 7?Simply move the create() into the connect method. Thanks! (answer from this article : dev.to/paulasantamaria/testing-nod...)
Thank you for your comment!
I've updated article using the latest @7.2.1 version of mongodb-memory-server.
Basically, I define a new instance of "MongoMemoryServer" in the
connect
async function to automatically start server:Ok! thanks a lot for your answer