我正在尝试创建一个索引,该索引返回带有键的对象中的排序数据。我的集合的默认索引返回如下内容:
{
"ref": Ref(Collection("posts"), "251333584234742292"),
"ts": 1583632773120000,
"data": {
"title": "A Great Title",
"sort_date": "2019-12-11",
"post_type": "blog",
"status": "published",
}
},...
我使用以下代码在 shell 中创建了一个索引:
CreateIndex({
name: "posts_sort_date_desc",
source: Collection("posts"),
values: [
{ field: ["data", "sort_date"], reverse: true },
{ field: ["data", "title"] },
{ field: ["data", "post_type"] },
{ field: ["data", "status"] },
{ field: ["ref"] }
]
}
当我查看这个新索引时,排序是正确的,但它看起来像一个没有键的数组,如下所示:
[
"2019-12-11",
"A Great Title",
"",
"published",
Ref(Collection("posts"), "254000373213168147")
], ...
有没有办法创建一个排序索引,只包含我需要的键值对数据?我浏览了文档,但无法弄清楚。谢谢。