Promisify mongo access in meteor?


#1

Here’s more or less the problem I am trying to avoid:

Classes.insert({
  name: "Class"
}, function(classErr, classId) {
  if(!classErr) {
    Instructors.insert({
      name: "Tim",
      classIds: [classId]
    }, function(err, teacherId) {
      if(!teacherErr) {
        return Students.insert({
          name: "Jeff",
          classIds: [classId],
          advisorId: teacherId
        })
      }
    })
  }
});

I think I want to add promises into my database to make the code more maintainable when using the models. Has anyone here implemented that before?