Considering those documents:
{
"Field1":"Test_1",
"Speaker":1,
"Listener":2,
"ListenTime": ISODate("2016-10-15T14:17:49.336Z")
},
{
"Field1":"Test_2",
"Speaker":1,
"Listener":2,
"ListenTime": ISODate("2016-10-13T14:17:49.336Z")
},
{
"Field1":"Test_3",
"Speaker":1,
"Listener":3,
"ListenTime": ISODate("2016-10-10T14:10:49.336Z")
}
What i what to do is to extract with a single query in MongoDB (3.2) only those documents grouping them by Speaker and Listener, taking only the document with the oldest ListenTime.
So, in this case, the result will be:
{
"Field1":"Test_1",
"Speaker":1,
"Listener":2,
"ListenTime": ISODate("2016-10-15T14:17:49.336Z")
},
{
"Field1":"Test_3",
"Speaker":1,
"Listener":3,
"ListenTime": ISODate("2016-10-10T14:10:49.336Z")
}
Is it possible do that with a single query?
Run the following aggregation pipeline to get the desired result:
Sample Output