【问题标题】:Fiware Orion: how to delete entities based on attribute valuesFiware Orion:如何根据属性值删除实体
【发布时间】:2016-02-11 13:25:22
【问题描述】:

我在 Orion 上下文代理中有许多实体,例如以下实体。 user_id 属性用于区分不同用户生成的实体。

{
    "_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
}

我想根据 user_id 属性的值删除一些此类实体。我尝试使用如下过滤功能(restriction 元素)来指定希望删除其实体的用户。 json 发布到 http://my_ip:my_port/v1/updateContext/,我指定了以下标题:Accept: application/jsonContent-Type: application/json

{
    "contextElements": [{
        "type": "Command",
        "id": "customCommands"
    }],
    "restriction": {
        "scopes": [{
            "type": "FIWARE::StringQuery",
            "value": "user_id==e260d1c6-f39e-4257-9f3e-91a82b281772"
        }]
    },
    "updateAction": "DELETE"
}

但是,我收到以下错误。

{
    "errorCode": {
        "code": "400",
        "reasonPhrase": "Bad Request",
        "details": "JSON Parse Error: unknown field: /restriction"
    }
}

是我做错了什么,还是限制对删除实体不起作用?如果是这种情况,我该怎么办?

【问题讨论】:

  • 我绕过了这个问题,将 user_id 使用分隔符移动到实体 id,如下所示,然后根据新 id 删除。 { "_id": { "id": "customCommands|e260d1c6-f39e-4257-9f3e-91a82b281772", "type": "Command", "servicePath": "/" }, "attrNames": ["command", "user_id"], "attrs": { "command": { "type": "string", "creDate": 1455195329, "modDate": 1455195329, "value": "RASPBERRY_ID" } }, "creDate": 1455195329, "modDate": 1455195329 }

标签: json messagebroker fiware-orion


【解决方案1】:

restriction 元素只能在queryContext 中使用。因此,不允许在 updateContext 中使用它,这解释了您收到的错误消息。

但是,一个简单的解决方法是分两步进行。首先,您使用queryContextrestriction 来删除所有实体。然后,您可以使用所有这些实体执行 updateContext,并将 updateAction 设置为 DELETE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多