2017-09-11 1 views
0

これは私のJsonです。私はprops.bom_concrete_type.idを持っていると私は "desc"を取得する必要がありますどのような種類のクエリが必要ですか?助けてくださいcouchbaseでJobjectのjson配列にアクセスするには? (SELECTクエリ)

[ 
    { 
    "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 by Client(Mining)", 
      "id": "15", 
      "shortname": null 
     } 
     ] 
    }, 
    "version": null 
    } 
] 

答えて

0

この種類のクエリでは、配列演算子(https://developer.couchbase.com/documentation/server/4.6/n1ql/n1ql-language-reference/collectionops.html)の1つを使用する必要があります。

上記のドキュメントをバケットに入力しましたが、これは「デフォルト」と呼ばれました。このクエリはあなたに 'desc'フィールドを与えます(これは予約語であるので、バックティックで引用する必要があります。 "order by ... desc")。

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

クエリ結果は次のとおりです。

[ 
    { 
    "desc": "Shotcrete" 
    } 
] 

あなただけの裸の価値をしたい場合は、このクエリを使用することができます。

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

と結果は以下のとおりです。

[ 
    "Shotcrete" 
] 
+0

ありがとうございました:) –

関連する問題