Reputation: 101
We need to sort documents using array field in the document using N1QL
We have following documents , PCI:
{
"id": "pci1",
"_class" = "PCI",
"productDSL": {
"parameters": {
"tpnb": ["02","04"]
}
}
},
{
"id": "pci2",
"_class" = "PCI",
"productDSL": {
"parameters": {
"tpnb": ["01","02","04"]
}
}
},
{
"id": "pci3",
"_class" = "PCI",
"productDSL": {
"parameters": {
"tpnb": ["01","02"]
}
}
},
{
"id": "pci4",
"_class" = "PCI",
"productDSL": {
"parameters": {
"tpnb": ["02","03"]
}
}
}
We need to "order by" according to the tpnb field which is an array. So the result should return in the following order
pci3,pci2,pci4,pci1
Upvotes: 0
Views: 138
Reputation: 7414
Try following query. ORDER is based on the array as whole
SELECT id FROM default
WHERE _class = "PCI"
ORDER BY productDSL.parameters.tpnb;
Upvotes: 2