2016-11-25 32 views
0

我JSON像下面N1QL陣列查詢的WHERE條件,以檢查內部elament

{ 
    "_id": "000fad10-b2de-11e6-92de-632a9b1d21d9", 
    "_type": "Company", 
    "status": 1, 
    "transactions": [ 
    { 
     "completed": 1, 
     "currency": "USD", 
     "date": "2015-12-01T18:30:00.000Z", 
     "method": 0, 
     "type": 0 
    } 
    ] 
} 

我想類似下面的查詢

select * from MyBucket where transactions.method in (0,3); 

運行我怎樣才能做到這一點在N1QL?

回答

2
SELECT * FROM MyBucket WHERE ANY x IN transactions SATISFIES x.method in[1,0] END; 

我這個

+0

yup,same sht(: – num8er

2

試試這個:

SELECT * FROM MyBucket b UNNEST b.transactions t WHERE t.method in [0,3]; 

保持這種cheatsheet

+0

得到答案,我錯過了 「[]」 在使用您的查詢,我得到4總JSON。 。 但我只有3.在一個JSON我有2個交易。 –

+2

不需要UNNEST:SELECT * FROM MyBucket WHERE transactions.method IN [0,3]; – geraldss

+0

你能看到這個問題嗎? http://stackoverflow.com/questions/40838443/want-to-sum-inner-element-with-json-in-using-n1qlcouchbase –