将属性添加到具有相同 ID 模式的多个创建的实体

Add attribute to multiple created entities with same id pattern

我没有在文档或源代码中找到将属性添加到具有相同 ID 模式的多个已创建实体的规范。只找到了将 attr 一个一个地添加到实体的方法(使用数组),但是当需要将属性添加到 100 多个具有 id 模式的实体时,this method 不起作用(惰性方法)(idIot:1,... , idIot:N).

有什么帮助吗?

允许一次更新多个实体的NGSIv2方法是POST /v2/op/update。它使用实体数组作为参数:

entities, an array of entities, each entity specified using the JSON entity representation format (described in the section "JSON Entity Representation").

在引用的“JSON 实体表示”部分我们有:

An entity is represented by a JSON object with the following syntax:

  • The entity id is specified by the object's id property, whose value is a string containing the entity id.
  • The entity type is specified by the object's type property, whose value is a string containing the entity's type name.
  • Entity attributes are specified by additional properties, whose names are the name of the attribute and whose representation is described in the "JSON Attribute Representation" section below. Obviously, id and type are not allowed to be used as attribute names.

因此,总而言之,您不能使用实体模式来更新。

但是,这有一个简单的解决方法:您可以创建一个脚本(或更广泛的程序中的逻辑函数)来完成这项工作,基本上:

  • 以给定的模式查询Orion,获取一组实体(考虑分页,如果实体数量很大)。
  • POST /v2/op/update更新所有这些实体(考虑到分批进行,因为如果要更新的实体数量很大,Orion 请求有 1MB 的限制)。

你可以看看this script,它是这样工作的(尽管在这种情况下是删除一组实体而不是更新属性)。