Saturday, 15 March 2014

javascript - How to automatically destroy 1-M connections in MongoDB and Meteor -


I am currently preparing a competing app that has a collection of collections, question collections, archives collections, and answer collections. My problem is that when I remove the contest, I do not know what is the best way to remove all the questions, answers and entries of any contest, thus I am handling this issue:

  Template.ContestItem.events ({'click .delete': function (e, tmpl) {e.preventDefault (); var currentContestId = ._id; var entries = entries.find ({contest_id: CurrentContestId}) var question = question.find ({contest_id: currentContestId}) reply answer = reply.find ({contes T_id: currentContestId}; answers.for each (work (reply) {answer quotation (answer.ID);}); question (northeast) (question (question) (question.line (question ._id);}); Entries (Entries) (Entries); Entries: Line (Entry._id);}) Competitions .remove (currentContestId);}});  

I think that though There should be a better way of ... My solution is being hacked together. I am not familiar with Mangodibi so it is a good thing Psht may mistake. Please tell me what a better way. Thanks!

This is my repo:

I will use the archive hook and package Remove all those items on the after.remove hook:

  Template.ContestItem.events ({'click .delete': function (e, tmpl) {E. PreventDefault (); Contests. Remove (this._id);});  

In some server code:

  competitions.after.remove (function (user id, contest) {entries.remove ({contest_id: contest._id} }); Q. Remove ({contest_id: contest._id}) Answer: Remove ({contest_id: contest._id});});  

No comments:

Post a Comment