Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a REST API With Express Modeling Data for the API Connecting Mongoose to MongoDB

Edvards Valbahs
PLUS
Edvards Valbahs
Courses Plus Student 23,881 Points

WARNING: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead

the warning appears after successful connection:

db connection successful Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html Saved! db connection closed

POSSIBLE SOLUTION (in your js file add mongoose.Promise = global.Promise; line before mongoose.connect ...):

mongoose.Promise = global.Promise; mongoose.connect("mongodb://localhost:27017/sandbox");

2 Answers

Edvards Valbahs
PLUS
Edvards Valbahs
Courses Plus Student 23,881 Points

POSSIBLE SOLUTION (in your js file add mongoose.Promise = global.Promise; line before mongoose.connect ...):

mongoose.Promise = global.Promise; 
mongoose.connect("mongodb://localhost:27017/sandbox");

This is not really an answer, just more info about what the error itself for any students watching going forward. The version used in the video is 4.4, as of today (July 14, 2017) current version is 4.11.2, depreciation happened with version 4.11.

@Andrew - fyi for the next round of video updates - thank you.

Full Error

(node:9044) DeprecationWarning: `open()` is deprecated in mon
goose >= 4.11.0, use `openUri()` instead, or set the `useMong
oClient` option if using `connect()` or `createConnection()`.
 See http://mongoosejs.com/docs/connections.html#use-mongo-cl
ient
db connection was successful, connected to : [object Object]
(node:9044) DeprecationWarning: Mongoose: mpromise (mongoose'
s default promise library) is deprecated, plug in your own pr
omise library instead: http://mongoosejs.com/docs/promises.ht
m

From Mongoose site:

The useMongoClient Option

Mongoose's default connection logic is deprecated as of 4.11.0. Please opt in to the new connection logic using the useMongoClient option, but make sure you test your connections first if you're upgrading an existing codebase!

// Using `mongoose.connect`...
var promise = mongoose.connect('mongodb://localhost/myapp', {
  useMongoClient: true,
  /* other options */
});

// Or `createConnection`
var promise = mongoose.createConnection('mongodb://localhost/myapp', {
  useMongoClient: true,
  /* other options */
});
promise.then(function(db) {
  /* Use `db`, for instance `db.model()`
});

// Or, if you already have a connection
connection.openUri('mongodb://localhost/myapp', { /* options */ });

The parameters to openUri() are passed transparently to the underlying MongoDB driver's MongoClient.connect() function. Please see the driver documentation for this function for options. The same is true for connect() and createConnection() if useMongoClient is true.

This deprecation is because the MongoDB driver has deprecated an API that is critical to mongoose's connection logic to support MongoDB 3.6, see this github issue for more details.