-1

I need help with a function nano.request(). I try get data by a request using a cloudant (couchdb) query but i no have idea how make it and i search anywhere. please i need help :P how search by query in a nano.request function??

thanks

var query = {
"selector": {
  "_id": {
    "$gt": 0
  },
  "Campaign_Id":9999
},
"fields": [
],
"sort": [
  {
    "_id": "asc"
  }
]};

cloudant.request({db: 'campaigns',
              method: 'get',
              doc: '_all_docs',
              qr: query 
            },function (err,data){
console.log(err);
console.log(data);
});
4

3 回答 3

2
var testRequest = function(query){

cloudant.request({db: 'campaigns',
                method: 'POST',
                doc: '_find',
                body: query
                },function (err,data){
                console.log(data);
});


 }



  var peticion = {
  "selector": {
     "crazy": true,
    "_id": {
      "$gt": 0
    }
  },
  "fields": [
    "_id",
    "_rev"
  ],
  "sort": [
    {
      "_id": "asc"
    }
  ]
}

  testRequest(peticion);
于 2016-07-25T19:58:23.743 回答
1

这不完全是您问题的答案,而只是一个建议。为什么不尝试使用搜索索引进行查询?我发现他们真的很棒。我已经从视图和查询转移到搜索索引。

于 2016-07-26T14:08:20.157 回答
0

您的查询看起来不错,但就像Rho所说,您需要先在字段上建立索引,然后才能使用 Cloudant Query。默认情况下,您的主索引位于_id.

您可以在 Cloudant 仪表板中构建索引。这是我的样子:在 Cloudant 仪表板中构建 Cloudant 查询索引

这是构建该索引的语法:

{
  "index": {
    "fields": [
      "Campaign_Id"
    ]
  },
  "type": "json"
}

这个想法是让它比定义 JavaScript MapReduce 视图更简单一些。Cloudant Query 还可以在您构建索引后执行即席查询"type": "text",但该索引的成本更高。更多信息请访问https://cloudant.com/blog/cloudant-query-grows-up-to-handle-ad-hoc-queries/

于 2016-07-26T12:50:37.720 回答