私は以下の要件を満たしています。 以下の配列要素では、LoanAmountの値を選択して比較する必要があります。前の記事では、以下の解決策が挙げられています。Cloudant Selector配列内の特定の要素を取得するクエリ
{
"_id": "65c5e4c917781f7365f4d814f6e1665f",
"_rev": "2-73615006996721fef9507c2d1dacd184",
"userprofile": {
"name": "tom",
"age": 30,
"employer": "Microsoft"
},
"loansBorrowed": [{"loanamount": 5000,
"loandate": "01/01/2001",
"repaymentdate": "01/01/2001",
"rateofinterest": 5.6,
"activeStatus": true,
"penalty": {
"penalty-amount": 500,
"reasonforPenalty": "Exceeded the date by 10 days"
}
},
{
"loanamount": 3000,
"loandate": "01/01/2001",
"repaymentdate": "01/01/2001",
"rateofinterest": 5.6,
"activeStatus": true,
"penalty": {
"penalty-amount": 400,
"reasonforPenalty": "Exceeded the date by 10 days"
}
},
{
"loanamount": 2000,
"loandate": "01/01/2001",
"repaymentdate": "01/01/2001",
"rateofinterest": 5.6,
"activeStatus": true,
"penalty": {
"penalty-amount": 500,
"reasonforPenalty": "Exceeded the date by 10 days"
}
}
]
}
Index:
{
"index": {
"fields": [{
"name": "loansBorrowed.[].loanamount",
"type":"number"
}],
"type": "json"
}
セレクタクエリ:
{"selector": {
"loansBorrowed": {
"$elemMatch": {
"loanamount": 3000
}
}
}
}
しかし、そのインデックスとセレクタクエリは、特定のクエリのすべてのレコードを提供する代わりに、私に3000 持つレコードのみを提供している唯一の特定の要素を取得する方法を提案してください。アレイブロックの内側にある。
すべてのレコードが返されるたびに、3000のloadamoutを含むsubloans要素がないことを確認してください。 $ elemMatchは一致した配列を取得しませんでしたので、ドキュメント全体が返されました。 –
非常に正確なdupe:https://stackoverflow.com/questions/33262573/cloudant-selector-query – xpqz
この場合、OPは具体的には配列内の特定の要素を返すことだけを求めています。それは他の郵便でも尋ねられましたが、実際には答えられませんでした。 – markwatsonatx