我想使用选择器查询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索引来索引只是您需要的特定字段。
关于json - Cloudant选择器查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33262573/