nosql - how to access json array in Jobject in couchbase? (SELECT query) -


this json. have props.bom_concrete_type.id , need "desc" kind of query need?? me

[   {     "create_date": "2017-06-07t09:35:12.2391092+08:00",     "id": "optional_dictionary",     "model": "optional_dictionary",     "props": {       "bom_concrete_type": [         {           "desc": "shotcrete",           "id": "1",           "shortname": null         },         {           "desc": "concrete",           "id": "2",           "shortname": null         }       ],       "bom_production_type": [         {           "desc": "underground",           "id": "1",           "shortname": null         },         {           "desc": "surface",           "id": "2",           "shortname": null         },         {           "desc": "tkajv",           "id": "3",           "shortname": null         }       ],       "mixorder_comment": [         {           "desc": "no order",           "id": "1",           "shortname": null         },         {           "desc": "client canceled",           "id": "2",           "shortname": null         },         {           "desc": "batch plant canceled",           "id": "3",           "shortname": null         },         {           "desc": "re-schedule/requester cancelled",           "id": "4",           "shortname": null         },         {           "desc": "batch plant shutdown",           "id": "5",           "shortname": null         },         {           "desc": "client shutdown",           "id": "6",           "shortname": null         },         {           "desc": "weather condition",           "id": "7",           "shortname": null         },         {           "desc": "client equipment",           "id": "8",           "shortname": null         },         {           "desc": "batch plant equipment",           "id": "9",           "shortname": null         },         {           "desc": "incident/accident",           "id": "10",           "shortname": null         },         {           "desc": "hse issue",           "id": "11",           "shortname": null         },         {           "desc": "client slow production",           "id": "12",           "shortname": null         },         {           "desc": "time conflict between requests",           "id": "13",           "shortname": null         },         {           "desc": "normal operation",           "id": "14",           "shortname": null         },         {           "desc": "slickline or underground maintenance client(mining)",           "id": "15",           "shortname": null         }       ]     },     "version": null   } ] 

for sort of query need use 1 of array operators (https://developer.couchbase.com/documentation/server/4.6/n1ql/n1ql-language-reference/collectionops.html).

i entered document above bucket called "default". query give 'desc' field (which needs quoted in back-ticks since reserved word, "order by...desc").

select first e.`desc`      e in props.bom_concrete_type when e.id = "1" end `desc`  default; 

the query result is:

[   {     "desc": "shotcrete"   } ] 

if want bare value, can use query:

select raw first e.`desc`    e in props.bom_concrete_type when e.id = "1" end  default; 

and results are:

[   "shotcrete" ] 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -