one method for using mongoose objects

23 views
Skip to first unread message

илья мотылев

unread,
Mar 7, 2014, 5:55:51 AM3/7/14
to mongoo...@googlegroups.com
This question duplicates http://stackoverflow.com/questions/22247186/one-method-for-using-mongoose-objects

I would like to create one method to call like this:
this.DoSomethingWithDb(this.someObject.findOne, conditions, this.RegisterDBCallback, additionalParams);

Inside DoSomethingWithDb I try to execute query, but it raise error.

myboj.prototype.DoSomethingWithDb = function DoSomethingWithDb(dbMethod, conditions, callback, params) {
    dbMethod
(conditions, function(err, doc) {
       
if (err) {

           
return;
       
}

       
if (typeof callback === 'function') {
            callback
(doc, params);
       
}

   
});
};

Part of error callstack:

....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)

илья мотылев

unread,
Mar 7, 2014, 7:59:42 AM3/7/14
to mongoo...@googlegroups.com

илья мотылев

unread,
Mar 7, 2014, 8:39:09 AM3/7/14
to mongoo...@googlegroups.com
Solved by passing query object onto DoSomethingWithDb
Reply all
Reply to author
Forward
0 new messages