Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'replace' of null (MongoClient.connect) #92

Open
glassdimly opened this issue Mar 11, 2019 · 0 comments

Comments

@glassdimly
Copy link

This is our code that we were using to connect to the mongo-mock, which works find in mongodb:

MongoClient.connect(process.env.MONGODB_CONFIG)
         |             ^
      63 |   .then(client => {
      64 |     mongo = client.db('myDb');

The problem was that mongo was depending on us passing in a dbname as the path parameter of the URL:

MongoClient.connect = function(url, options, callback) {
...
  url = urlparse(url);
...
  var dbname = url.pathname.replace(/^\//, '');
  return new Db(dbname, server).open(callback);

...We were not passing in dbname.

The workaround was this:

MongoClient.connect(process.env.MONGODB_CONFIG + '/myDb')
.then(client => {
  mongo = client;

...That is, I needed to send the db in as a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant