我想标识对象数组(嵌入式文档)中存在的重复项,并希望返回重复项(条件应为startDate
属性)以及该文档从集合中的主键。
Mongodb文档结构:
{
"_id" : "123",
"timeZone" : "Australia/Queensland",
"schedule" : [
{
"startDate" : ISODate("2018-07-09T16:00:00.000Z"),
"endDate" : ISODate("2018-07-09T16:30:00.000Z"),
"day" : "MONDAY",
"status" : "AVAILABLE"
},
{
"startDate" : ISODate("2018-07-09T16:30:00.000Z"),
"endDate" : ISODate("2018-07-09T17:00:00.000Z"),
"day" : "MONDAY",
"status" : "AVAILABLE"
},
{
"startDate" : ISODate("2018-07-09T16:30:00.000Z"),
"endDate" : ISODate("2018-07-09T17:00:00.000Z"),
"day" : "MONDAY",
"status" : "AVAILABLE"
}
]
}
我正在寻找Spring mongodb聚合代码,该代码应返回_ids
和重复的schedule elements
的列表。像这样:
[
{
"_id" : "123",
"schedule" : [
{
"startDate" : ISODate("2018-07-09T16:30:00.000Z"),
"endDate" : ISODate("2018-07-09T17:00:00.000Z"),
"day" : "MONDAY",
"status" : "AVAILABLE"
},
{
"startDate" : ISODate("2018-07-09T16:30:00.000Z"),
"endDate" : ISODate("2018-07-09T17:00:00.000Z"),
"day" : "MONDAY",
"status" : "AVAILABLE"
}
]
},
{
Another document containing _ids and duplicates
}
]