如何在对象数组中排序-CouchBase [英] How to sort in array of object - CouchBase

查看:84
本文介绍了如何在对象数组中排序-CouchBase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,目前我想对对象数组进行排序,我使用ARRAY_SORT函数,它将使用对象的第一个字段对&如果每个对象都具有相同的JSON结构,则效果很好。如果数组中的一个元素具有不同的JSON结构,则结果不正确。

Hi currently I want to sort array of object, I use ARRAY_SORT function, it will use the first field of object to sort & it work well if every object has the same JSON structure. If one element in array has different JSON structure, the result is incorrect.

我使用的查询:

SELECT ARRAY_SORT(c.student) as student FROM Class c

结果:

"student": [
  {
    "id": 3,
    "name": "Kenny35"
  },
  {
    "id": 6,
    "name": "Kenny35"
  },
  {
    "id": 7,
    "name": "Kenny35"
  },
  {
    "id": 8,
    "name": "Kenny35"
  },
  {
    "hobby": "video game",
    "id": 5,
    "name": "Kenny35"
  }
]

如何为ARRAY_SORT函数指定数组中对象的属性?

How can I specify property of object in array for ARRAY_SORT function ?

推荐答案

dev,
首先比较对象的长度/大小,然后再比较对象中的字段。
http://developer.couchbase .com / documentation / server / 4.5 / n1ql / n1ql-language-reference / comparisonops.html

这是目前唯一支持的排序规则。
-Prasad

That is the only collation supported now. -Prasad

这篇关于如何在对象数组中排序-CouchBase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆