哪个是将蓝鸟与猫鼬一起使用的正确方法?
Which is the right way to use bluebird with mongoose?
来自蓝鸟文档:
// Mongoose
var Promise = require("bluebird");
Promise.promisifyAll(require("mongoose"));
来自猫鼬文档:
var mongoose = require("mongoose");
// Use bluebird
mongoose.Promise = require('bluebird');
我应该使用哪一个?
这里有两个讨论
People asked for promises support and Mongoose is quite a mature library now over 4 years old- mpromise was chosen because it looked like a good way to add promise support at a time.
所以我们可以从bluebird中找到这个用法,
Promise.promisifyAll(require("mongoose"));
mongoose.Promise = require('bluebird');
will make mongoose use native promises. You should be able to use any ES6 promise constructor though, but right now we only test with native, bluebird, and Q
所以两个都OK
来自蓝鸟文档:
// Mongoose
var Promise = require("bluebird");
Promise.promisifyAll(require("mongoose"));
来自猫鼬文档:
var mongoose = require("mongoose");
// Use bluebird
mongoose.Promise = require('bluebird');
我应该使用哪一个?
这里有两个讨论
People asked for promises support and Mongoose is quite a mature library now over 4 years old- mpromise was chosen because it looked like a good way to add promise support at a time.
所以我们可以从bluebird中找到这个用法,
Promise.promisifyAll(require("mongoose"));
mongoose.Promise = require('bluebird');
will make mongoose use native promises. You should be able to use any ES6 promise constructor though, but right now we only test with native, bluebird, and Q
所以两个都OK