Press "Enter" to skip to content

关于nodejs使用mongoose连接mongodb的一个错误

控制台错误如下:

DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html

大概意思是缺少了promise库,去网址http://mongoosejs.com/docs/promises.html 看了下。
在标题为: Plugging in your own Promises Library 的下面,有写到。大概意思是说promisemongoose 4.1.0 以后将已插件的形式存在

解决

    var query = Band.findOne({name: "Guns N' Roses"});

    // Use native promises 使用本地的promises
    mongoose.Promise = global.Promise;
    assert.equal(query.exec().constructor, global.Promise);

    // Use bluebird 使用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);

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code