1

I have the following array of data inside the data bucket SITES in my Couchbase server

"siteMaster": [
                {
                    "sitename": "HTS_SITE_001",
                    "sitelink": "http://facebook.com",
                    "address" : "19/2, Bellandur, Bangalore India",
                    "filename": "site1.json",
                    "persons": 1,
                    "status": "70%",
                    "contact": "[email protected]",
                }, {
                    "sitename": "HTS_SITE_002",
                    "sitelink": "http://facebook.com",
                    "address": "5th Avenue, New York",
                    "filename": "site2.json",
                    "persons": 1,
                    "status": "70%",
                    "contact": "[email protected]",
                }, {
                    "sitename": "HTS_SITE_003",
                    "sitelink": "http://facebook.com",
                    "address": "Palo Alto, California",
                    "filename": "site3.json",
                    "persons": 1,
                    "status": "80%",
                    "contact": "[email protected]",
                }, {
                    "sitename": "HTS_SITE_004",
                    "sitelink": "http://facebook.com",
                    "address": "Bellandur, Bangalore",
                    "filename": "site4.json",
                    "persons": 1,
                    "status": "80%",
                    "contact": "[email protected]",
                }
            ]

The N1QL query for

select * from SITES where status = "70%" should return me two rows, but unfortunately it is not returning any rows.

Where am I going wrong with the query ?

1
  • Please upgrade to Couchbase 4.1 or 4.5 DP. Commented Mar 31, 2016 at 18:10

1 Answer 1

1

Please use the following query:

SELECT *
FROM SITES
WHERE ANY sm IN siteMaster SATISFIES sm.status = "70%" END;

You can also create the following array index to speed up the query:

CREATE INDEX idx ON SITES( DISTINCT ARRAY sm.status FOR sm IN siteMaster END );
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to select the indexes into siteMaster that match?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.