mongodb $ addToSet在另一个$ addToSet中添加

时间:2017-03-21 13:03:04

标签: mongodb mongodb-query aggregation-framework

在这个addToSet"唯一":"控制器","模块"和"变量"是独特的领域, 如果任何一个字段更改意味着它将插入完整的"唯一的"它的工作正常,  但我需要插入如果唯一字段保持相同的意思 我需要插入新的" cal"数组关闭"日期时间"和"价值",我该怎么做?

db.measurement.update({"siteId":"55","thingId":"IOT",
    "unique.controller":11.0,"unique.module":10.0,"unique.variable":"curent"},
    {$addToSet:{
        "unique": {
        "controller":11,
        "module": 10.0,
        "variable" : "curent",
        "calculation" : [ 
                {
                    "min" : "a",
                    "max" : "c",
                    "avg" : "",
                    "cal" : [ 
                        {
                            "Datetime" : "",
                            "value" : 345.0
                        }
                    ]
                }
            ]
    }}}); 

这是我的收藏:

{

    "siteId" : "55",
    "thingId" : "IOT",
    "Date" : 1234545.0,
    "unique" : [ 
        {
            "controller" : 11.0,
            "module" : 10.0,
            "variable" : "curent",
            "calculation" : [ 
                {
                    "min" : "",
                    "max" : "",
                    "avg" : "",
                    "cal" : [ 
                        {
                            "Datetime" : "",
                            "value" : 345.0
                        }
                    ]
                }
            ]
        }, 
        {
            "controller" : 11.0,
            "module" : 10.0,
            "variable" : "curent",
            "calculation" : [ 
                {
                    "min" : "",
                    "max" : "c",
                    "avg" : "",
                    "cal" : [ 
                        {
                            "Datetime" : "",
                            "value" : 345.0
                        }
                    ]
                }
            ]
        }, 
        {
            "controller" : 11.0,
            "module" : 10.0,
            "variable" : "curent",
            "calculation" : [ 
                {
                    "min" : "a",
                    "max" : "c",
                    "avg" : "",
                    "cal" : [ 
                        {
                            "Datetime" : "",
                            "value" : 345.0
                        }
                    ]
                }
            ]
        }
    ],
    "thingType" : "",
    "moduleType" : 91.0,
    "enabled" : 1.0,
    "variableType" : "AI",
    "updatedTime" : NumberLong(1483209000),
    "requestedValue" : "",
    "requestedTime" : 0.0
}

这是我试过的:

db.measurement.update({"siteId":"55","thingId":"IOT",
    "unique.controller":11.0,"unique.module":10.0,"unique.variable":"curent"},
    {$addToSet:{
        "unique": {
        "controller":11,
        "module": 10.0,
        "variable" : "curent",
        "calculation" : [ 
                {
                    "min" : "a",
                    "max" : "c",
                    "avg" : "",
                    "cal" : [ 
                        {
                            "Datetime" : "",
                            "value" : 345.0
                        }
                    ]
                }
            ]
    }}}); 

0 个答案:

没有答案