I am new to Mongodb lets say i need to insert 3 documents
in 3 different collections
for example lets say i have a department
, students
and department_membership
collections. when department head add one student
to the department
, so that time i need insert document like
{ _id: 123, name: "st_name", email: "test@gmail.com" }
in student
collection
{ _id: 2356, dept_id: 12 , added_by_whom_id: 253, student_id: 123}
in department
collection
{ _id: 13111, dept_id: 12, student: { _id: 123, name: "st_name" } }
in department_membership
collection
what i want is to either insert all documents in respective collections or it should fail all insert, how to handle this?