Context:
My database has two collections: "Users" and "Files".
Sample document from "Users" collection:
{
"username":"Adam",
"email":"[email protected]",
"IdFilesOwned":[1,3],
}
As you can see, Adam currently owns two files on the server. Their ids are 1 and 3.
Sample documents from "Files" collection:
{
"fileId":1,
"name":"randomPNG.png"
}
{
"fileId":2,
"name":"somePDF.pdf"
}
{
"fileId":3,
"name":"business.pdf"
}
As you can see, I have three documents on my server, each document having an id and some metadata.
Now, Adam wants to see all the files that he owns, and their metadata. The way i would implement this, is:
1.Lookup the array of file ids that Adam owns.
2.Have node.js run through each id (using a for each loop), and query the metadata for each id.
The problem is that nodejs will make multiple queries (1 query per id). This seems very inefficient. So my question is if there is a better way to implement this?
IdFilesOwned
, justFilesOwned
)?