我在用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 | trans = 1539588749-153-00000013561 |来自= some.ip | srv = some_tenant | subsrv = / some_subtenant | comp = Orion | op = AlarmManager.cpp [211]:dbError | msg =正在发出警报DatabaseError:nextSafe():{$ err:“执行程序错误:OperationFailed:排序操作使用的RAM超过最大33554432字节。添加索引或指定更小的限制。”,代码:17144} 时间= 2018-10-16T07:47:36.576Z | lvl =错误| corr = bf8461dc-d117-11e8-b0f1-0242ac110003 | trans = 1539588749-153-00000013561 |来自= some.ip | srv = some_tenant | subsrv = / some_subtenant | comp = Orion | 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"
}
]
答案 0 :(得分:1)
您有一个索引/** @test */
public function a_user_can_see_the_landing_page()
{
$response = $this->get('/');
$response->assertStatus(200);
}
/** @test */
public function a_user_who_isnt_signed_in_is_redirected_to_login()
{
$response = $this->get(route('home'));
$response->assertRedirect(route('login'));
}
,如果您使用{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 }
EDIT2 :请查看this section in documentation,以获取有关此类索引的更多详细信息。