Mongo node-JS驱动程序:分组,排序和限制查询

时间:2016-11-22 14:23:48

标签: node.js mongodb

我在Mongo中有一个数据集,我试图通过Node JS驱动程序查询。具体来说,我试图按字段(域)分组,按日期排序(DTG),然后限制为1条记录(最新记录)。

数据的一个例子:

{'Domain':'google.com', 'DTG': datetime.datetime(2016, 11, 17, 16, 23, 2, 920000)}
{'Domain':'google.com', 'DTG': datetime.datetime(2016, 11, 15, 16, 23, 2, 920000)}
{'Domain':'google.com', 'DTG': datetime.datetime(2016, 11, 12, 16, 23, 2, 920000)}
{'Domain':'yahoo.com', 'DTG': datetime.datetime(2016, 11, 17, 16, 27, 41, 714000)}
{'Domain':'yahoo.com', 'DTG': datetime.datetime(2016, 11, 11, 16, 27, 41, 714000)}
{'Domain':'yahoo.com', 'DTG': datetime.datetime(2016, 11, 10, 16, 27, 41, 714000)}
{'Domain':'bing.com', 'DTG': datetime.datetime(2016, 11, 17, 16, 27, 43, 714000)}

我想要得到的输出是:

{'Domain':'google.com', 'DTG': datetime.datetime(2016, 11, 17, 16, 23, 2, 920000)}
{'Domain':'yahoo.com', 'DTG': datetime.datetime(2016, 11, 17, 16, 27, 41, 714000)}
{'Domain':'bing.com', 'DTG': datetime.datetime(2016, 11, 17, 16, 27, 43, 714000)}

我一直在拖网Mongo Node驱动程序文档,并且一直在尝试使用$ group运算符,但到目前为止都没有成功。

0 个答案:

没有答案