I am learning node.js + express + mongoose. I have an application that posts collection of documents that I want to do a bulk operation on. Each document has an ID, It should look through the database by id. If it exists, update the document, if not, create it. If document has a deletion flag, then delete. When all of these operations are done, return with all the documents in DB.
sample documents
[{_id: "5a278bbc-8b95-de77-4788-29a4d026dfc8", name: "doing",isDelete: true},
{_id: "9d852c99-2b14-06dd-6cd0-a34396b98668", name: "todo",isDelete: true},
{_id: "cb4bf8f8-027d-8435-4d75-6aa50635461d", name: "doing", isDelete: true},
{_id: "ee17a83b-acda-0ff4-c266-7037771d3b55", name: "Another", createdOn: “"},
{_id: "c48baa68-dec2-f23d-017e-5ac9f8c7687b", name: "todo", createdOn: “"},
{_id: "dd4ba88c-f109-363c-f818-393bfd9b6a58", name: "Beans", createdOn: “"},
{_id: "e141a9e8-afa8-98ee-fa97-20f425c93b6f", name: "Cool", createdOn: “"}]
In my research, I read up about initializeOrderedBulkOp. But Im not sure how that works for me doing lookups, updates and deletions at the same time. And how to respond with res.send, when the operations are done