Cloudant选择器查询

编程入门 行业动态 更新时间:2024-10-22 16:38:05
本文介绍了Cloudant选择器查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用选择器使用cloudant db进行查询,例如下面所示:用户希望借入金额超过数字的借贷,如何在cloudant选择器中访问数组以查找特定记录

I would like to query using cloudant db using selector, for example that is shown below: user would like to have loanborrowed whose amount exceeds a number, how to access the array in a cloudant selector to find a specific record

{ "_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索引(键入text,对所有内容建立索引):

If you use the default Cloudant Query index (type text, index everything):

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

然后下面的查询选择器应该可以找到例如所有贷款额大于1000的文档:

Then the following query selector should work to find e.g. all documents with a loanamount > 1000:

"loansBorrowed": { "$elemMatch": { "loanamount": { "$gt": 1000 } } }

我不确定您是否可以哄骗Cloudant查询仅对数组中的嵌套字段编制索引,因此,如果您不需要为所有内容编制索引"方法的灵活性,那么最好创建Cloudant搜索索引只索引您需要的特定字段.

I'm not sure that you can coax Cloudant Query to only index nested fields within an array so, if you don't need the flexibility of the "index everything" approach, you're probably better off creating a Cloudant Search index which indexes just the specific fields you need.

更多推荐

Cloudant选择器查询

本文发布于:2023-10-30 04:30:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541771.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选择器   Cloudant

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!