php - 如何通过 php 按 mongodb 上的嵌套对象排序?
问题描述
我需要有关如何根据嵌套文档对 mongodb 查询进行排序的帮助
这是我试过的
$options = ['sort' => ['stats' => ['points' => 1]]];
$query = new MongoDB\Driver\Query([],$options);
这是 mongo 对象的架构
{
"_id" : ObjectId("5d0cd19c811d53277225fc33"),
"uuid" : "a2277fa1-07df-4c19-902a-93ae7e2795a1",
"name" : "ImAleex_",
"stats" : {
"points" : 1000,
"kills" : 1,
"losses" : 1,
"wins" : 1
},
"info" : {
"lastRankeds" : NumberLong(1561128665478),
"lastConnection" : NumberLong(1561128834286),
"lastModifiedKit" : NumberLong(1561215124553),
"rankeds" : 5,
"visibility" : true,
"chat" : true,
"fly" : false,
"requests" : true,
"menuRequests" : true
}
}
我在 Apache 日志 ConnectionException: bad sort specification 上收到此错误消息
解决方案
尝试 :
$options = ['sort' => ['stats.points' => 1]];
$query = new MongoDB\Driver\Query([],$options);
推荐阅读
- python - For循环Python-来自Matlab
- c# - Visual Studio 2017 错误:找不到“”的项目信息这可能表明缺少项目引用 - 使用 Console App .NET Core 2.1
- python - python open cv中的图像日志转换
- c# - 将 T 实体传递给 EventHandler
- rest - Azure RBAC Rest API 调用以获取对象类型
- ios - ARKit - 点击屏幕后物体卡在相机上
- c# - 日期上的 newtonsoft 序列化程序给出不同的结果
- sql - SQL选择在所有行中具有相同值的项目
- sql - 将 N Unicode 附加到字符串文字
- excel - Microsoft Navision 和 Odata Uri 通过 Excel 网络服务功能