I have a nodeJS system where a student enrolls for a batch, and so i have a field in the mongodb as batchSize which holds maximum number of students in one batch, student can enroll on a batch and batchSize should reduce its value
how to write a query to do the same?
Batch.update({ _id: data.batch._id }, { $push: { 'students': data.student }, $inc: { currentlySubscribed: 1 } }
Batch.update({ _id: data.batch._id }, { $pull: { 'students': { 'email': data.student.email } }, $inc: { currentlySubscribed: -1 } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With