jedireza / mongo-models

:package: Map JavaScript classes to MongoDB collections
MIT License
67 stars 28 forks source link

MongoClient.connect function incompatible with Node MongoDB 3.6 driver #27

Closed andyfry01 closed 6 years ago

andyfry01 commented 6 years ago

Hello!

The MongoClient.connect method in the MongoDB 3.6 driver has changed. See the changelog for more info, beginning with "MongoClient.connect works as expected but it returns...". MongoClient.connect no longer returns the database, but an instance of MongoClient.

So the connect method will have to be refactored to something like the following:

static connect(uri, dbName options, callback) { 
        Mongodb.MongoClient.connect(uri, options, (err, client) => {
            if (err) {
                return callback(err);
            }
            MongoModels.db = client.db(dbName);
            callback(null, db);
        });
 }

Or maybe the dbName could be included in the options object.

Happy to do a pull request.

jedireza commented 6 years ago

Thanks for sharing this.

So it looks like 3.0.0 was just released on December 24th. https://github.com/mongodb/node-mongodb-native/blob/HEAD/HISTORY.md#300-2017-12-24

Since a major version bump will be a breaking change maybe we should get these changes into #25.

A PR is more than welcome. Please fork the async-await-and-multiple-connections and create a PR against that branch. 🙏

jedireza commented 6 years ago

This will be resolve with #25