I have a number of entities in Orion context broker such as the following one. The user_id attribute is used to distinguish entities generated by different users.
{
"_id": {
"id": "customCommands",
"type": "Command",
"servicePath": "/"
},
"attrNames": ["command", "user_id"],
"attrs": {
"command": {
"type": "string",
"creDate": 1455195329,
"modDate": 1455195329,
"value": "RASPBERRY_ID"
},
"user_id": {
"type": "string",
"creDate": 1455195329,
"modDate": 1455195329,
"value": "e260d1c6-f39e-4257-9f3e-91a82b281772"
}
},
"creDate": 1455195329,
"modDate": 1455195329
}
I would like to delete a number of such entities based on the value of the user_id attribute. I tried using filtering capabilities (restriction element) as follows to specify the users who want their entities removed. The json is posted to http://my_ip:my_port/v1/updateContext/ and I specified the following headers: Accept: application/json and Content-Type: application/json
{
"contextElements": [{
"type": "Command",
"id": "customCommands"
}],
"restriction": {
"scopes": [{
"type": "FIWARE::StringQuery",
"value": "user_id==e260d1c6-f39e-4257-9f3e-91a82b281772"
}]
},
"updateAction": "DELETE"
}
However, I get the following error.
{
"errorCode": {
"code": "400",
"reasonPhrase": "Bad Request",
"details": "JSON Parse Error: unknown field: /restriction"
}
}
Am I doing something wrong, or restrictions do not work to delete entities? If this is the case, how can I do it?
The restriction
element can be used only in queryContext
. Thus, using it in updateContext
is not allowed and that explains the error message you are getting.
However, an easy workaround is working in two steps. First, you use queryContext
with the restriction
to get all the entities to delete. Then you can do an updateContext
with all these entities and updateAction set to DELETE
.