0

I would like to delete multiple rows at once in Mongoose but I can only think/find of doing this with an each and removing individually.

var arrays = [ [ 560324b994a552efdeb128a2 ],
  [ 560324b994a552efdeb128a3 ],
  [],
  [],
  [],
  [ 560324b994a552efdeb128a0 ],
  [ 560324b994a552efdeb128a1 ],
  [] ]

someModel.remove(arrays);

Also if possible I'd like it to remove only the items that have a value, although this is easy to overcome if I need to remove them.

1 Answer 1

1

You can remove multiple documents with the $in query operator as follows

var idsArray = ['560324b994a552efdeb128a0', '560324bd5f4f4df6s128a0'];

someModel.remove({ id: { $in: idsArray } }, function (err) {
    if (err) return callback("Error while deleting " + err.message);
    callback(null, "Some useful message here...");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.