Cloudant选择器查询 [英] Cloudant Selector Query

查看:101
本文介绍了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选择器查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆