I am looking for some recommendations on how best to approach this type of query in MongoDB.
I have a shopping base, each of which has a property course, as well as the date on which the person bought.
I want the shopping list to happen after someone bought the original product.
So - some pesudo requests here:
{ course: 'a' }
then
/*
out of those people, filter for those who in the future signed up
for another course
*/
{
course: { $in: ['b','c','d']},
date: { $gt: $courseA.purchaseDate }
}
Is this possible through aggregation? Or would I make several database calls for each initial purchase to check if there is a future?
Here is an example of how the data for each purchase will look:
{ email: 'wes@example.com', course: 'a', purchaseDate: 10 },
{ email: 'wes@example.com', course: 'b', purchaseDate: 20 }, // match
{ email: 'wes@example.com', course: 'c', purchaseDate: 5 }, // not
{ email: 'nancy@example.com', course: 'a', purchaseDate: 5 },
{ email: 'nancy@example.com', course: 'c', purchaseDate: 6 }, // match
{ email: 'nancy@example.com', course: 'b', purchaseDate: 10 }, // match
{ email: 'nancy@example.com', course: 'd', purchaseDate: 1 }, // not