Here's my requirement
Pass a array of id's to some function which will do the following
Check if a document exists in Mongodb if YES skip to next id if No create a document with specified id
If all id's of array exist in db return a message all id's exist if not return message created missing documents
Tried several ways to do it but nothing was successful as desired.
Problems I ran into, missing documents created but the message all id's exist returned first before creation completed.
Tried using async but dint help. tried using array length and count of found docs this returned undefined.
**I'm using mongo native client and there's absolutely no problem with mongo queries in this case. The problem is with Node.js . node executes all at once, before the previous step has finished and I understand node is not sequential. since looking for a document and creating it takes time the next steps are executed first and then after all DB process is completed. I'm looking for a solution that will go step by step in a sequence.