Mongodb-memory-server: Probably incorrect documentation

Created on 14 Oct 2018  路  3Comments  路  Source: nodkz/mongodb-memory-server

I'm trying to use the module as described in docs.

const MongodbMemoryServer = require('mongodb-memory-server');
const mongoServer = new MongodbMemoryServer();

But I got the error TypeError: MongodbMemoryServer is not a constructor.

At this page I've found another piece of code

const mongoServer = new MongodbMemoryServer.MongoMemoryServer();

and that works. Is that an error in the documentation or in the code?

Most helpful comment

Also, it is possible to use:

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

It worked for me.

All 3 comments

@kbychkov The documentation is actually using the ES6 equivalent syntax of require that is import :

import MongodbMemoryServer from 'mongodb-memory-server';

const mongod = new MongodbMemoryServer();

By using import like that, it is actually importing the default export of the mongodb-memory-server library that is MongodbMemoryServer. A easy way to do that with require is this :

const MongodbMemoryServer = require('mongodb-memory-server').default
const mongoServer = new MongodbMemoryServer()

Ahhh, I see. Thank you for the explanation!

Also, it is possible to use:

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

It worked for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EnergeticPixels picture EnergeticPixels  路  3Comments

frederikheld picture frederikheld  路  6Comments

alexandrulesi picture alexandrulesi  路  8Comments

machadogj picture machadogj  路  11Comments

hasezoey picture hasezoey  路  7Comments