gpt4 book ai didi

json - Cloudant 选择器查询

转载 作者:行者123 更新时间:2023-12-04 02:55:09 24 4
gpt4 key购买 nike

我想通过使用选择器使用 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 查询索引(输入文本,索引所有内容):

{
"index": {},
"type": "text"
}

然后下面的查询选择器应该可以找到例如贷款金额 > 1000 的所有文件:
"loansBorrowed": { "$elemMatch": { "loanamount": { "$gt": 1000 } } }

我不确定您是否可以哄骗 Cloudant Query 仅索引数组中的嵌套字段,因此,如果您不需要“索引所有内容”方法的灵活性,您可能最好创建一个 Cloudant Search 索引来索引只是您需要的特定字段。

关于json - Cloudant 选择器查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33262573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com