我有以下文档
{
"_id": "products:info",
"_rev": "3-47add0ce8ecbcb2c4c7dfefae83c02cd",
"created": "01-26-2022",
"products": [
{
"brand": "MSI",
"title": "Summit e16",
"sku": "1000121"
},
{
"brand": "MSI",
"title": "Summit e13",
"sku": "1000120"
}
]
}
我想按 desc 顺序products
按属性对数组进行排序sku
并获得第一个产品 sku。
到目前为止,我尝试了以下操作。
指数
{
"type": "json",
"partitioned": true,
"def": {
"fields": [
{
"products[].sku": "asc"
}
]
}
}
询问
{
"selector": {
"products": {
"$elemMatch": {
"sku": {
"$ne": null
}
}
}
},
"fields": [
"_id",
"products.0.sku"
],
"sort": [
{
"products.sku": "desc"
}
]
}
投掷错误
Error running query. Reason: (no_usable_index) No global index exists for this sort, try indexing by the sort fields.
也尝试了以下
{"products.sku": "desc"}
{"products.[].sku": "desc"}