【发布时间】:2016-10-02 08:33:19
【问题描述】:
我在mongodb中有如下数据结构
[
{
"id" : "unique id 1",
"timeStamp" : "timeStamp",
"topicInfo" : [
{
topic : "topic1",
offset : "offset number",
time: 1464875267637
},
{
topic : "topic2",
offset : "offset number",
time: 1464875269709
},
{
topic : "topic3",
offset : "offset number",
time : 1464875270849
}
]
},
{
"id" : "unique id 2",
"timeStamp" : "timeStamp",
"topicInfo" : [
{
topic : "15",
offset : "offset number",
time : 1464875271884
},
{
topic : "topic2",
offset : "offset number",
time : 1464875273887
},
{
topic : "topic3",
offset : "offset number",
time : 1464875272848
}
]
}
]
现在我想找到所有具有名为“topic2”的主题的条目,并且与“topicInfo”数组中的其他对象相比,时间的值是最大值。我还想按“时间戳”对它们进行排序。从示例代码中,查询应该返回第二个对象。我无法编写查询任何帮助将不胜感激。
【问题讨论】:
-
为什么你的文档中有“时间”字符串?
-
对不起,我正在编辑它。实际上是以毫秒为单位的时间。
标签: node.js mongodb mongodb-query aggregation-framework