Mahsum Akbas
Mahsum Akbas

Reputation: 1583

Get nested object from json in couchbase with N1QL

I have following json as an entry in Couchbase:

{
    "messageType": "TRANS",
    "failCount": 0,
    "workOrderDetailMap": {
        "10873": {
            "requestDate": "20160715151239",
            "id": 10873,
            "responseDate": "20160715151305",
            "responseCode": 0,
            "status": "SUCCESS",
            "resultDocuments": [
                "xyz"
            ]
        }
    }
}

and I want to get resultCode field by N1QL query :

Select * from myproject where workOrderDetailMap.responseCode = 0;

I got 0 result.

How can I do that ?

Upvotes: 0

Views: 961

Answers (1)

geraldss
geraldss

Reputation: 2445

You need

select * from myproject where workOrderDetailMap.`10873`.responseCode = 0;

If you need to ignore the 10873:

select * from myproject where object_values(workOrderDetailMap)[0].responseCode = 0;

Upvotes: 7

Related Questions