跳到主要内容
CNode

mongoos 的 findOne 方法 回调函数 err 和 doc 两个参数都为null

问答
Zzmzkkk发布于 10 年前最后回复 10 年前
241810

m.statics.info = function(groupId){ var _this = this; return new Promise(function (resolve, reject){ _this.findOne({_id:groupId},function(err,doc){
console.log(err); console.log(doc); if(!err){ resolve(doc); }else{ reject(err); } }); }); }

为什么 mongoos 的 findOne 方法 回调函数 err 和 doc 两个参数都为null

查看回复

回复 (2)

M
mosaic101#210 年前

明显使用不对,看api,可以直接返回Promise对象

M
merrynode#110 年前

##- -应该是找不到匹配的doc mongoose支持Promise的,不需要再包一层Promise 推荐使用原生或者bluebird替换掉mongoose的Promise

var mongoose = require('mongoose');
mongoose.Promise = Promise;

参与回复

登录后即可参与回复。登录