如何查询同一天和小时中有20个或更多文档的日期
我有一个像这样的蒙古多德数据库结构,
{
_id: ObjectId,
name: string,
scheduledDate: ISOString
}
我想返回所有在所有数据库中重复2次或以上的计划日期,
示例:
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-15T05:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-15T07:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-18T02:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-18T02:20:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-18T02:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-10T05:44:00.000Z"
}
在此示例2022-04-15中,重复2次和2022-04-18重复3次,因此两者都符合标准(2次或更多),所以我想返回两个日期 这可能吗?
这样:
{
scheduledDate:"2022-04-15T00:00:00.000Z"
},
{
scheduledDate:"2022-04-18T00:00:00.000Z"
}
还有一个问题,可以在小时数中做同样的事情吗?在所有数据库x times中重复的计划日期的特定小时列表
I have a mongoDB database structure like this
{
_id: ObjectId,
name: string,
scheduledDate: ISOString
}
I want to return all scheduledDates that repeat the same scheduledDate day 2 times or more across all the database
Example:
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-15T05:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-15T07:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-18T02:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-18T02:20:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-18T02:44:00.000Z"
},
{
_id: ObjectId,
name: 'example1',
scheduledDate: "2022-04-10T05:44:00.000Z"
}
In this example 2022-04-15 repeats 2 times and 2022-04-18 repeat 3 times, so both match the criteria (2 times or more) so I want to return both date day
Is this possible?
Like this:
{
scheduledDate:"2022-04-15T00:00:00.000Z"
},
{
scheduledDate:"2022-04-18T00:00:00.000Z"
}
And one more question, is possible to do the same with hours? A list of specific hours of scheduledDate that repeat across all database X times
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
$ group
带有$ date
和$ datetunc
mongoplayground
Use
$group
with$date
and$dateTrunc
mongoplayground