var query =Band.findOne({name:"Guns N' Roses"});assert.ok(!(query instanceofrequire('mpromise')));// A query is not a fully-fledged promise, but it does have a `.then()`.query.then(function (doc) {// use doc });// `.exec()` gives you a fully-fledged promisevar promise =query.exec();assert.ok(promise instanceofrequire('mpromise'));promise.then(function (doc) {// use doc });
var query =Band.findOne({name:"Guns N' Roses"});// Use native promisesmongoose.Promise =global.Promise;assert.equal(query.exec().constructor,global.Promise);// Use bluebirdmongoose.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() instanceofrequire('q').makePromise);
var uri ='mongodb://localhost:27017/mongoose_test';// Use bluebirdvar options = { promiseLibrary:require('bluebird') };var db =mongoose.createConnection(uri, options); Band =db.model('band-promises', { name: String });db.on('open',function() {assert.equal(Band.collection.findOne().constructor,require('bluebird')); });