node.js - How can I find another Mongoose document (by ID) from a document's instance method? -
my model saves id of "parent" (in tree structure). in 1 of instance methods, want edit parent. there way can via id? model.findbyid
doesn't work, obviously. have access function in other way?
you can access doc's model in instance method via this.constructor
; can as:
regionschema.methods.addupdatedata = function(contents, callback) { this.constructor.findbyid(this.parentid, function(err, doc) { ... }); }
Comments
Post a Comment