如何使用日期时间类型字段创建聚合?

我正在尝试在MongoDB中编写查询。我需要使用datetime字段“加入”两个集合。

例如,我的两个收藏如下:

Collection 1
{ 
 "_id" : ObjectId("00001"),"text" : "Example 1","datetime" : ISODate("2019-10-26T12:26:40Z") 
},{ 
 "_id" : ObjectId("00002"),"text" : "Example 2","datetime" : ISODate("2019-10-26T12:40:30Z") 
},{ 
 "_id" : ObjectId("00003"),"text" : "Example 3","datetime" : ISODate("2019-10-28T12:26:40Z") 
}

Collection 2
{ 
 "_id" : ObjectId("000011"),"meaasure" : 10,"datetime" : ISODate("2019-10-26T12:00:00Z") 
},{ 
 "_id" : ObjectId("000012"),"meaasure" : 15,"datetime" : ISODate("2019-10-28T12:00:00Z") 
}

我想截断datetime字段,仅保留日期和小时,然后将集合1对象与集合2中的度量值分组

对于上面的示例,输出必须类似于:

{ 
 "text" : "Example 1","datetime_collection1" : ISODate("2019-10-26T12:26:40Z") 
 "datetime_collection2" : ISODate("2019-10-26T12:00:00Z")  
},{ 
 "text" : "Example 2","datetime_collection1" : ISODate("2019-10-26T11:30:40Z") 
 "datetime_collection2" : ISODate("2019-10-26T12:00:00Z") 
},"datetime_collection1" : ISODate("2019-10-28T12:26:40Z") 
 "datetime_collection2" : ISODate("2019-10-28T12:00:00Z") 
}


我希望我的问题很清楚。 预先感谢您能提供的任何帮助。

sxdtzzf 回答:如何使用日期时间类型字段创建聚合?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3155160.html

大家都在问