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

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -