These are chat archives for Automattic/mongoose

26th
Sep 2016
Paul Lucas
@pauljlucas
Sep 26 2016 00:20 UTC
anyone have any tips on removing multiple docs at once while also triggering the post("remove") middleware? i know how to do it one at a time but that seems horribly innefficient
``` model .find({
_id: { $in: notificationIds }
})
.exec()
.then(function(returnedDocs: any) {
returnedDocs
.remove()
.then(function () {
deferred.resolve();
model  .find({
            _id: { $in: notificationIds }
        })
        .exec()
        .then(function(returnedDocs: any) {
            returnedDocs
                .remove().exec()
                .then(function () {
                    deferred.resolve();
The remove isnt even triggering here with or without exec following it.
Paul Lucas
@pauljlucas
Sep 26 2016 00:35 UTC
i know it is because returned docs is an array of docs but i dont want to have to loop through this and call remove unless that is the most efficient way to do it in mongo
Sebastien Vaucouleur
@vaucouleur
Sep 26 2016 09:29 UTC
Hi, If there is a gridfs-stream expert around, a tip would be greattly appreciated: I'm using gridfs-stream "createWriteStream" to upload data, and it works very nicely. My only issue is that it's not clear how to get the _id of the newly created "fs.files document" since the "finish" event does not seems to pass any information. Any idea ? So far, I could work around this problem by using "metadata" , but right now, having this _id would be very useful.
LeonineKing1199
@LeonineKing1199
Sep 26 2016 21:19 UTC

@pauljlucas

I know that the remove method takes a query object. Would that not be sufficient for your case?