Fix duplicate name situation due to entities created before Orion 0.17.0 -


since orion 0.17.0 attribute type no longer used attribute "identification key". however, have entities created pre-0.17.0 version have attributes same name , different types. example, following entity, have "activepower" duplicated:

> db.entities.findone({"_id.type": "regulator", "_id.id": "outsmart.rg_las_llamas_01", "_id.servicepath": "/"}) {     "_id" : {         "type" : "regulator",         "id" : "outsmart.rg_las_llamas_01",         "servicepath" : "/"     },     "attrs" : [         {             "name" : "timeinstant",             "value" : "2015-04-27t01:51:36.000000z",             "type" : "urn:x-ogc:def:trs:idas:1.0:iso8601",             "moddate" : 1430092302         },         {             "name" : "activepower",             "value" : "11778",             "type" : "urn:x-ogc:def:phenomenon:outsmart:1.0:activepower",             "moddate" : 1430092302         },         {             "name" : "reactivepower",             "value" : "8414",             "type" : "urn:x-ogc:def:phenomenon:outsmart:1.0:reactivepower",             "moddate" : 1430092302         },         {             "name" : "electricpotential",             "value" : "231",             "type" : "urn:x-ogc:def:phenomenon:idas:1.0:electricpotential",             "moddate" : 1430092302         },         {             "name" : "electriccurrent",             "value" : "20890",             "type" : "urn:x-ogc:def:phenomenon:idas:1.0:electriccurrent",             "moddate" : 1430092302         },         {             "name" : "latitud",             "value" : "43.4716987609863",             "type" : "urn:x-ogc:def:phenomenon:idas:1.0:latitude",             "moddate" : 1414522843         },         {             "name" : "longitud",             "value" : "-3.80692005157471",             "type" : "urn:x-ogc:def:phenomenon:idas:1.0:longitude",             "moddate" : 1401818472         },         {             "name" : "activepower",             "credate" : 1393420396,             "value" : "11778.2",             "type" : "float",             "moddate" : 1430092302         }     ],     "moddate" : 1430092302 } 

how can adapt entity work orion 0.17.0 , beyond?

the simplest solution edit entity using mongo console, remove "duplicated" attributes same name , leave one. in example above have 1 activepower type urn:x-ogc:def:phenomenon:outsmart:1.0:activepower , other type float. let's assume want kept first one.

first of all, stop orion , take backup of database. if gets wrong while edit entity, need backup go initial status , try again.

next, run mongo console (let's assume db named "orion") , entity modify using findone() operation. let's store in doc variable.

# mongo orion > doc = db.entities.findone({"_id.type": "regulator", "_id.id": "outsmart.rg_las_llamas_01", "_id.servicepath": "/"}) ... 

now, identify position within attrs array of attribute remove, taking account position of first element in vector 0 (and not 1). looking above example, attribute remove 7-th. check printing attribute:

> doc.attrs[7] {     "name" : "activepower",     "credate" : 1393420396,     "value" : "11778.2",     "type" : "float",     "moddate" : 1430092302 } 

use splice() function remove attribute doc, using first parameter position of attribute , second parameter 1. print doc value check has been removed:

> doc.attrs.splice(7, 1) ... > doc 

repeat above operation many time need remove duplicated (in example case, there 1 duplicated). when done, save new version of entity in db:

> db.entities.save(doc) 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -