【发布时间】: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