In this addToSet "unique":"controller", "module" and "variable" are unique fields, if any one fields change means it will insert full "unique" and its working fine, but i need to insert if unique fields remain same means i need to insert new "cal"array off "Datetime" and "value",how to i do that?
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
}
]
}
]
}}});
This is my collection:
{
"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
}
This was i tried:
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
}
]
}
]
}}});