Mongoose驱动程序方法没有返回承诺

时间:2016-07-08 01:02:51

标签: node.js mongodb mongoose

使用mongoose@4.4.20 bluebird@3.4.1 mongodb@3.0.20 node@4.4.7

根据mongoose文档,我已经指定了这样的promise库。

const mongoose = require('mongoose'),
      Promise = require('bluebird');
mongoose.Promise = Promise;
mongoose.connect('db_uri', {promiseLibrary: Promise});

但是,根据节点mongodb驱动程序文档和源代码的预期,驱动程序方法返回undefined

MyModel.collection.insertOne(doc); //undefined
MyModel.collection.updateMany(criteria, update); //undefined
MyModel.collection.find(criteria); //not even a cursor, undefined
//...and so on

另一个回答here的问题解释了行为,但它依赖于回调。

如何使用promises的驱动程序方法而不像这样MyModel.collection.method(...).then(...).catch(...)手动宣传它们?

0 个答案:

没有答案
相关问题