How to get particular field in couchbase document

n1ql

#1

I want to check whether particular journeyid exist in 12345678 document, how to achieve this functionality.Below is my document

{
“uiid”: “c815c6c9-da0e-3759-62e6-ef89aa685fb3”,
“orders”: [
{
“payload”: {
"__version": 1,
“orderRequest”: {
"__version": “2”,
“grandTotal”: 300,
“customerUiid”: “c815c6c9-da0e-3759-62e6-ef89aa685fb3”,
“totalShippingCostBeforeTax”: 0,
“journeyID”: “e69122fe-17c2-e173-0e0c-403bde1e2091”,
“shipments”: [
{
“lineItems”: [
{
“unitPrice”: 45,
“amountBeforeTax”: 90,
}
],
"__version": “2”,
“shipmentNumber”: “d1746ecb-97dc-4b49-f4f6-43c7ec2c6540”,
"__type": “shipment”
}
],
“storeCode”: “17ba38fb-f170-6e7c-16df-55fde93ef780”
}
}
},

{
  "payload": {
    "__version": 1,
    "orderRequest": {
      "__version": "2",
      "grandTotal": 300,
       "customerUiid": "c815c6c9-da0e-3759-62e6-ef89aa685fb3",
      "totalShippingCostBeforeTax": 0,
       "journeyID": "f69122fe-17c2-e173-0e0c-403bde1e2091",
      "shipments": [
        {
          "lineItems": [
            {
              "unitPrice": 45,
              "amountBeforeTax": 90,
                        }
          ],
          "__version": "2",
          "shipmentNumber": "d1746ecb-97dc-4b49-f4f6-43c7ec2c6540",
          "__type": "shipment"
        }
      ],
      "storeCode": "17ba38fb-f170-6e7c-16df-55fde93ef780"
    }
  }
}

],

}


How to check document has exist a field
#2

Hi, you should look up the Couchbase documentation on SELECT-FROM-WHERE.


#3

SELECT * FROM bucket_name use keys “12345678” WHERE journeyid=“e69122fe-17c2-e173-0e0c-403bde1e2091”;

Or if you just want to check if the field isn’t missing you can use is not missing.

SELECT * FROM bucket_name use keys “12345678” WHERE journeyid IS NOT MISSING;

For more details look at :
http://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/comparisonops.html

http://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/collectionops.html