如何在数组模式中找到具有最小“结束日期时间”值的文档?

时间:2019-05-19 05:21:14

标签: mongodb mongoose

我想使用以下架构在集合中找到相应的文档。 如何在Meetings数组架构中获取endDtime的最大值并找到那些文档的最小值?

email: { type: String, require: true, unique: true },
password: { type: String, require: true },
meetings: [{
   startDtime: UTC DateTime,
   endDtime: UTC DateTime
}]

示例:

{
   email: "test1",
   meetings: [{
      startDtime: "2019-03-01 11:00:00",
      endDtime: "2019-03-01 12:00:00"
   },
   {
      startDtime: "2019-03-03 11:00:00",
      endDtime: "2019-03-03 12:00:00",
   }]
},
{
   email: "test2",
   meetings: [{
      startDtime: "2019-01-11 11:00:00",
      endDtime: "2019-01-11 12:00:00"
   },
   {
      startDtime: "2019-03-04 11:00:00",
      endDtime: "2019-03-04 12:00:00",
   }]
}

"test1" -> maximum value "meeting.endDtime" : "2019-03-03 12:00:00"
"test2" -> maximum value "meeting.endDtime" : "2019-03-04 12:00:00"

i want to find "test1"

0 个答案:

没有答案