First of all sorry if the title does not reflect what I really need to do.
Imagine a collection that represents what products sell which vendor. Let´s simplify like:
{_id, productID, VendorID, Price, Stock}
For example, we could have:
{_id: 1 ,productID: 1, vendorID: A, price: 0, stock: 0},
{_id: 2 ,productID: 2, vendorID: A, price: 0, stock: 0},
{_id: 3 ,productID: 3, vendorID: A, price: 0, stock: 0},
{_id: 4 ,productID: 4, vendorID: A, price: 0, stock: 0},
{_id: 5 ,productID: 1, vendorID: B, price: 0, stock: 19},
{_id: 6 ,productID: 3, vendorID: B, price: 0, stock: 21}
The idea is that Vendor A is the Super Admin and the one who controls which products can be sold in the marketplace. That´s why all products sold by A have price = 0 and stock = 0.
What I am trying to get within the same query is. When Vendor B is logged:
- List all the items that A is selling.
- But if a product is sold by B, then I should return it instead of the A-one.
The result would look like:
{_id: 2 ,productID: 2, vendorID: A, price: 0, stock: 0},
{_id: 4 ,productID: 4, vendorID: A, price: 0, stock: 0},
{_id: 5 ,productID: 1, vendorID: B, price: 0, stock: 19},
{_id: 6 ,productID: 3, vendorID: B, price: 0, stock: 21}
Do you have any idea how I can do it in a shot?
I can do the filter in the frontend but I would prefer doing like this in order to avoid problems with pagination for example.