Requirement: I want a collection of all customers who did not perform the "View" event in last 5 hours
.
Data:
{
name: "Sheldon",
events: [
{
event: "View",
timestamp: "timestamp equivalent to 10 hours ago"
},
{
event: "Some other event",
timestamp: "timestamp equivalent to 8 hours ago"
},
{
event: "View",
timestamp: "timestamp equivalent to 2 hours ago"
}
]
},
{
name: "Leonard",
events: [
{
event: "View",
timestamp: "timestamp equivalent to 10 hours ago"
}
]
},
{
name: "Howard",
events: [
{
event: "View",
timestamp: "timestamp equivalent to 2 hours ago"
}
]
},
{
name: "Raj",
events: [
{
event: "Some other event",
timestamp: "timestamp equivalent to 6 hours ago"
}
]
}
I have tried out the following, but it always returns "Sheldon"
(possibly because the other event ends up satisfying the criteria?).
q.where({
$and: [
{
'events': {
$not: {
$elemMatch: {
event: "View",
timestamp: {
$gte: "timestamp equivalent to 5 hours ago"
}
}
}
}
}
]
});
What can I do so that only documents for "Leonard"
and "Raj"
are returned?