使用mongoose进行数据库操作时,总是提示:
(node:5684) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
解决方法:
在
之前加一句:
最后:
这样就好了。
http://mongoosejs.com/docs/promises.html
Plugging in your own Promises Library
New in Mongoose 4.1.0
While mpromise is sufficient for basic use cases, advanced users may want to plug in their favorite ES6-style promises library like bluebird, or just use native ES6 promises. Just set mongoose.Promise
to your favorite ES6-style promise constructor and mongoose will use it.
Mongoose tests with ES6 native promises, bluebird, and q. Any promise library that exports an ES6-style promise constructor should work in theory, but theory often differs from practice. If you find a bug, open an issue on GitHub
var query = Band.findOne({name: "Guns N' Roses"});
// Use native promises
mongoose.Promise = global.Promise;
assert.equal(query.exec().constructor, global.Promise);
// Use bluebird
mongoose.Promise = require('bluebird');
assert.equal(query.exec().constructor, require('bluebird'));
// Use q. Note that you **must** use `require('q').Promise`.
mongoose.Promise = require('q').Promise;
assert.ok(query.exec() instanceof require('q').makePromise);