【问题标题】:Error on querying FIWARE Orion with orderBy custom attribute使用 orderBy 自定义属性查询 FIWARE Orion 时出错
【发布时间】:2018-10-15 10:42:06
【问题描述】:

我在使用 orderBy 查询 Orion 时遇到以下问题,要求结果按时间顺序返回。我的数据如下所示:

{
    "id": "some_unique_id",
    "type": "sensor",
    "someVariable": {
        "type": "String",
        "value": "1",
        "metadata": {}
    },
    "datetime": {
        "type": "DateTime",
        "value": "2018-09-21T00:38:57.00Z",
        "metadata": {}
    },
    "humidity": {
        "type": "Float",
        "value": 55.9,
        "metadata": {}
    },
    "someMoreVariables": {
        "type": "Float",
        "value": 6.29,
        "metadata": {}
    }

我的电话是这样的:

http://my.ip.com:1026/v2/entities?type=sensor&offset=SOMENUMBERMINUS30&limit=30&orderBy=datetime

不幸的是,响应如下:

{
"error": "InternalServerError",
"description": "Error at querying MongoDB"}

调用中同时使用租户和子租户,而 Orion 版本为 1.13.0-next,租户已在 MongoDB 内部建立索引。我从同一服务器中的不同 Docker 实例运行 Orion 和 MongoDB。 一如既往,我们将不胜感激任何帮助。

EDIT1:经过fgalan的推荐,我正在从日志中添加相关记录(对不起,我从一开始就没有这样做):

BadInput some.ip 时间=2018-10-16T07:47:36.576Z | lvl=错误 | corr=bf8461dc-d117-11e8-b0f1-0242ac110003 |反式=1539588749-153-00000013561 |从=一些.ip | srv=some_tenant | subsrv=/some_subtenant | comp=猎户座 | op=AlarmManager.cpp[211]:dbError | msg=Raising alarm DatabaseError: nextSafe(): { $err: "Executor error: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. 添加索引,或指定更小的限制。",代码:17144 } 时间=2018-10-16T07:47:36.576Z | lvl=错误 | corr=bf8461dc-d117-11e8-b0f1-0242ac110003 |反式=1539588749-153-00000013561 |从=一些.ip | srv=some_tenant | subsrv=/some_subtenant | comp=猎户座 | op=AlarmManager.cpp[235]:dbErrorReset | msg=解除告警DatabaseError

从上面可以看出,索引是必需的。根据 fgalan 对我过去另一个问题的回答,我已经这样做了:Indexing Orion

EDIT2:索引后的 Orion 响应:

[
    {
            "v" : 2,
            "key" : {
                    "_id" : 1
            },
            "name" : "_id_",
            "ns" : "orion.entities"
    },
    {
            "v" : 2,
            "key" : {
                    "location.coords" : "2dsphere"
            },
            "name" : "location.coords_2dsphere",
            "ns" : "orion.entities",
            "2dsphereIndexVersion" : 3
    },
    {
            "v" : 2,
            "key" : {
                    "creDate" : 1
            },
            "name" : "creDate_1",
            "ns" : "orion.entities"
    }
]

【问题讨论】:

  • 您能否编辑您的问题以包含 contexBroker 日志?它们对于调试案例非常有用。谢谢!
  • 非常感谢@fgalan 的快速回复。我已经编辑了我的问题并包含了日志。
  • 我们越来越近了... ;) 请问您能否在您的数据库中添加索引配置?我的意思是运行mongo <db>(如果您使用默认配置,<db> 通常是orion),然后运行db.entities.getIndexes()。谢谢!
  • 通过执行 use orion 并在 getIndexes 之后,我收到以下响应:[{"v":2,"key":{"id":1},"name": "_id","ns":"orion.entities"},{"v":2,"key":{"location.coords":"2dsphere"},"name":"location.coords_2dsphere ","ns":"orion.entities","2dsphereIndexVersion":3},{"v":2,"key":{"creDate":1},"name":"creDate_1","ns": "orion.entities"}]
  • 请在问题正文中添加响应(作为 EDIT 2 块)。谢谢!

标签: fiware-orion


【解决方案1】:

您有一个索引 {creDate: 1},如果您使用 dateCreated 按实体创建日期排序(或未指定 orderBy 参数,因为创建日期是默认排序),则该索引很好:

GET /v2/entities
GET /v2/entities?orderBy=dateCreated

但是,如果您计划按您定义的不同属性进行排序(据我所知datetime 是)并得到OperationFailed: Sort operation used more than the maximum 错误,那么您必须为此类属性的值创建一个索引。特别是你必须创建这个索引:

{ attrs.datetime.value: 1 }

编辑: 正如对此答案的评论所建议的,创建上述索引的命令通常是:

db.entities.createIndex({"attrs.datetime.value": 1});

EDIT2:查看this section in documentation,了解有关此类索引的更多详细信息。

【讨论】:

  • 我明白了。非常感谢!
  • 一个注意事项,重点一定要引用。所以最后的命令是 db.entities.createIndex({"attrs.datetime.value": 1});
  • 好点。已编辑答案以包含该操作系统信息。谢谢!
  • fiware-orion.readthedocs.io/en/master/admin/perf_tuning/… 的文档已改进以描述此类索引
  • 这很有帮助!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
相关资源
最近更新 更多