FIWARE-STH Comet 如何为每次更新创建不同的记录?

How to create different record for every update in FIWARE-STH Comet?

我刚开始使用 FIWARE,我在处理要保留在 MongoDB 上的数据时遇到了问题。我想在最小模式下使用 STH Comet。我正在使用 Python 脚本创建具有特定 ID 的上下文数据,然后更新此数据的某些属性。当我观察来自此脚本和 HTTP 请求的 JSON 数据时,我看不出有任何问题,但 MongoDB 仅在相关集合中保留此数据的最新更新版本。此外,“sth”标记的集合不会显示。但是我可以在属性中看到“credate”和“moddate”元数据。但是我每次更新都需要不同的记录。

这是我发送给 Orion 以创建上下文数据的第一个 POST 请求:

{"id": "urn:ngsi-ld:entity:001", 
"type": "Log",
"a": {"type": "Datetime", "value": "17/09/2021"}, 
"b": {"type": "Datetime", "value": "12:00:18.0"}, 
"c": {"type": "Integer", "value": 49.51}, 
"d": {"type": "Integer", "value": 175.35}, 
"e": {"type": "Integer", "value": 24.25}, 
"f": {"type": "Integer", "value": 999.1}, 
"g": {"type": "Integer", "value": 85.87}, 
"h": {"type": "Integer", "value": -0.01}, 
"i": {"type": "Integer", "value": 37.41}, 
"j": {"type": "Integer", "value": 60.65}}

这是我在 MongoDB 集合中得到的,attrNames 已针对该问题设为虚拟:

{
  "_id": {
    "id": "urn:ngsi-ld:entity:001",
    "type": "Log",
    "servicePath": "/"
  },
  "attrNames": [
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "j"
  ],
  "attrs": {
    "a": {
      "type": "Datetime",
      "creDate": 1645514416,
      "modDate": 1645514416,
      "value": "17/09/2021",
      "mdNames": []
    },
    "b": {
      "value": "12:00:21.0",
      "type": "Datetime",
      "mdNames": [],
      "creDate": 1645514416,
      "modDate": 1645514597
    },
    "c": {
      "value": 666.47,
      "type": "Integer",
      "mdNames": [],
      "creDate": 1645514416,
      "modDate": 1645514640
    },
    "d": {
      "value": 175.55,
      "type": "Integer",
      "mdNames": [],
      "creDate": 1645514416,
      "modDate": 1645514597
    },
    "e": {
      "value": 24.27,
      "type": "Integer",
      "mdNames": [],
      "creDate": 1645514416,
      "modDate": 1645514597
    },
    "f": {
      "value": 999.28,
      "type": "Integer",
      "mdNames": [],
      "creDate": 1645514416,
      "modDate": 1645514597
    },
    "g": {
      "type": "Integer",
      "creDate": 1645514416,
      "modDate": 1645514416,
      "value": 85.87,
      "mdNames": []
    },
    "h": {
      "type": "Integer",
      "creDate": 1645514416,
      "modDate": 1645514416,
      "value": -0.01,
      "mdNames": []
    },
    "i": {
      "type": "Integer",
      "creDate": 1645514416,
      "modDate": 1645514416,
      "value": 37.41,
      "mdNames": []
    },
    "j": {
      "value": 1111.47,
      "type": "Integer",
      "mdNames": [],
      "creDate": 1645514416,
      "modDate": 1645514640
    }
  },
  "creDate": 1645514416,
  "modDate": 1645514640,
  "lastCorrelator": "679e1cba-93b0-11ec-be0f-0242ac120102" 

这是我用STH Comet Query得到的数据输出:

{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "c",
                        "values": [
                            {
                                "_id": "621ca977165813000740898e",
                                "recvTime": "2022-02-28T10:52:39.012Z",
                                "attrName": "c",
                                "attrType": "Integer",
                                "attrValue": 49.47
                            },
                            {
                                "_id": "621ca97d165813000740899e",
                                "recvTime": "2022-02-28T10:52:45.581Z",
                                "attrName": "c",
                                "attrType": "Integer",
                                "attrValue": 49.61
                            },
                            {
                                "_id": "621ca98316581300074089a7",
                                "recvTime": "2022-02-28T10:52:51.239Z",
                                "attrName": "c",
                                "attrType": "Integer",
                                "attrValue": 49.46
                            },
                            {
                                "_id": "621ca98916581300074089ac",
                                "recvTime": "2022-02-28T10:52:57.662Z",
                                "attrName": "c",
                                "attrType": "Integer",
                                "attrValue": 49.57
                            },
                            {
                                "_id": "621ca98d16581300074089b9",
                                "recvTime": "2022-02-28T10:53:01.852Z",
                                "attrName": "c",
                                "attrType": "Integer",
                                "attrValue": 49.47
                            },
                            {
                                "_id": "621ca99316581300074089c7",
                                "recvTime": "2022-02-28T10:53:07.242Z",
                                "attrName": "c",
                                "attrType": "Integer",
                                "attrValue": 49.41
                            },
                            {
                                "_id": "621ca9a116581300074089d2",
                                "recvTime": "2022-02-28T10:53:21.305Z",
                                "attrName": "c",
                                "attrType": "Integer",
                                "attrValue": 49.51
                            }
                        ]
                    }
                ],
                "id": "urn:ngsi-ld:entity:001",
                "isPattern": false,
                "type": "Log"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

如你所见,我可以在返回的查询中获得MongoDB _id,但问题是,我无法在相关的MongoDB中找到这些单独数据的位置数据库。

我已经浏览了所有文档,但要么找不到解决方案,要么是我遗漏了架构逻辑中的某些内容。我该如何解决这个问题?

谢谢!

简单来说,我意识到我遇到的问题是由于我没有在 STH Comet 的 config.js 文件中更改参数我在远程服务器上设置。

因此,我更改了 config.server 部分中的 host 参数(从 "localhost""server's own IP")和 URI 参数(从 "localhost:27017""serversIP:27017") 在文件的 config.database 部分。

系统现在按预期工作。