1

我的Couchbase 服务器的数据桶SITES中有以下数据数组

"siteMaster": [
                {
                    "sitename": "HTS_SITE_001",
                    "sitelink": "http://facebook.com",
                    "address" : "19/2, Bellandur, Bangalore India",
                    "filename": "site1.json",
                    "persons": 1,
                    "status": "70%",
                    "contact": "max.smith@honeywell.com",
                }, {
                    "sitename": "HTS_SITE_002",
                    "sitelink": "http://facebook.com",
                    "address": "5th Avenue, New York",
                    "filename": "site2.json",
                    "persons": 1,
                    "status": "70%",
                    "contact": "john.smith@facebook.com",
                }, {
                    "sitename": "HTS_SITE_003",
                    "sitelink": "http://facebook.com",
                    "address": "Palo Alto, California",
                    "filename": "site3.json",
                    "persons": 1,
                    "status": "80%",
                    "contact": "steve.jobs@apple.com",
                }, {
                    "sitename": "HTS_SITE_004",
                    "sitelink": "http://facebook.com",
                    "address": "Bellandur, Bangalore",
                    "filename": "site4.json",
                    "persons": 1,
                    "status": "80%",
                    "contact": "max.mustermann@deutsche.com",
                }
            ]

N1QL 查询

select * from SITES where status = "70%" 应该返回两行,但不幸的是它没有返回任何行。

我的查询哪里出错了?

4

1 回答 1

1

请使用以下查询:

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

您还可以创建以下数组索引以加快查询速度:

CREATE INDEX idx ON SITES( DISTINCT ARRAY sm.status FOR sm IN siteMaster END );
于 2016-04-01T05:49:18.997 回答