-1
通过查询,并将其传递到DoSomethingWithDb解决:一个使用猫鼬Method对象
var query = TestModel.findOne({numField: 1});
DoSomethingWithDb = function DoSomethingWithDb(dbMethod, callback, params) {
....
}
我想创建一个方法,像这样调用:
this.DoSomethingWithDb(this.someObject.findOne, conditions, this.RegisterDBCallback, additionalParams);
里面DoSomethingWithDb我试着执行查询,但会引发错误。错误调用堆栈的
myboj.prototype.DoSomethingWithDb = function DoSomethingWithDb(dbMethod, conditions, callback, params) {
dbMethod(conditions, function(err, doc) {
if (err) {
return;
}
if (typeof callback === 'function') {
callback(doc, params);
}
});
};
部分:
....node_modules\mongoose\lib\model.js:949 this._applyNamedScope(query); ^TypeError: Object # has no method '_applyNamedScope' at findOne (...\node_modules\mongoose\lib\mode l.js:949:8) at DoSomethingWithDb (....server.js:2103:2)
你一般会在你的猫鼬模型添加为一个静态/实例方法。请你可以发布你的模型代码? – Alex
这里完整的测试代码http://pastebin.com/0Qz52KzJ 我试着在这里粘贴代码,但代码长度太长。 – Ilya
你不应该编辑你的问题,把“解决”,你需要回答它。 – Alex