我想使用选择器使用cloudant db进行查询,例如下面所示:用户希望借入的借贷金额超过数字,如何在cloudant选择器中访问数组以查找特定记录
{ "_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" } } ] }
如果您使用默认的Cloudant Query索引(键入文本,对所有内容建立索引):
{ "index": {}, "type": "text" }
然后,以下查询选择器应可以查找例如所有借贷金额> 1000的文档:
"loansBorrowed": { "$elemMatch": { "loanamount": { "$gt": 1000 } } }
我不确定您是否可以哄骗Cloudant查询仅索引数组中的嵌套字段,因此,如果您不需要“为所有内容建立索引”的灵活性,那么最好创建一个Cloudant Search索引来索引只是您需要的特定字段。