在date范围内查询Mongodb集合

我有一个收集以下文件:

var interactions = [ { _id: 54ed77eec55b18101e82f205, email: 'customercare@tikona.in', contactCompanyName: 'tikona', contactFullName: 'Customercare', contactValue: 0, "interactionDate": "2016-03-30T08:28:58.000Z", }, { _id: 54ed77eec55b18101e82f205, email: 'inbox@google.com', contactCompanyName: 'google', contactFullName: 'inbox', contactValue: 0, "interactionDate": "2016-03-30T08:28:58.000Z", }, { _id: 54ed77eec55b18101e82f205, email: 'nazar@zinavo.com', contactCompanyName: 'zinavo', contactFullName: 'nazar', contactValue: 0, "interactionDate": "2016-03-25T08:28:58.000Z", }, { _id: 54ed77eec55b18101e82f205, email: 'nazar@zinavo.com', contactCompanyName: 'zinavo', contactFullName: 'nazar', contactValue: 0, "interactionDate": "2016-03-26T08:28:58.000Z", }, { _id: 54ed77eec55b18101e82f205, email: 'nazar@zinavo.com', contactCompanyName: 'zinavo', contactFullName: 'nazar', contactValue: 0, "interactionDate": "2016-03-13T08:28:58.000Z", }, { _id: 54ed77eec55b18101e82f205, email: 'inbox@google.com', contactCompanyName: 'google', contactFullName: 'inbox', contactValue: 0, "interactionDate": "2016-04-06T08:28:58.000Z", }, { _id: 54ed77eec55b18101e82f205, email: 'nazar@zinavo.com', contactCompanyName: 'zinavo', contactFullName: 'nazar', contactValue: 0, "interactionDate": "2016-04-03T08:28:58.000Z", }] 

如何查询这个集合,使interactionDate大于或等于过去60天,但小于或等于过去30天。 即我需要从2016年2月12日至2016年3月12日,然后从2016年3月12日至2016年4月12日查找并统计这些文件,然后find这两个date范围之间的交互计数之间的差异。

我试过的技巧

获取这两个date范围的互动。 例如

 { '$gte': Fri Feb 12 2016 11:29:29 GMT+0530 (IST), '$lte': Tue March 12 2016 11:29:29 GMT+0530 (IST) } 

然后运行第二个查询:

 { '$gte': Fri Marc 12 2016 11:29:29 GMT+0530 (IST), '$lte': Tue Apr 12 2016 11:29:29 GMT+0530 (IST) } 

然后,为每个电子邮件,减去交互计数。

聚合查询:

 { $match:{ {"interactions.email":{$in:emailArr}}} }, { $group:{ _id: "$interactions.email", count: { $sum: 1} } }, { $sort: {"count" : -1} }, { $project:{ email: "$_id", interactionCount : "$count", _id : 0, }