识别对象数组(嵌入式文档)中的重复项,并从集合中返回主键(_ids)

时间:2019-02-08 07:04:48

标签: mongodb aggregation-framework spring-data-mongodb

我想标识对象数组(嵌入式文档)中存在的重复项,并希望返回重复项(条件应为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

}  

] 

0 个答案:

没有答案