I have a collection of users with comments as an embedded document:
{
id : "01",
username : "john",
comments : [
{
id : "001",
body : "this is the comment",
timestamp : 2012-04-23T18:25:43.511Z
},
{
id : "002",
body : "this is the 2nd comment",
timestamp : 2015-03-22T18:25:43.511Z
}
]
}
Now I would like to query for comments from a given timespan (let's say newer than 48 hours) with an associated username. In this case I would like to get the following JSON:
{
username : "john",
comments : [
{
id : "002",
body : "this is the 2nd comment",
timestamp : 2015-03-22T18:25:43.511Z
}
]
}
How can I achieve it using MongoDB and mongoose?