如何通过设计文档调用curl请求来获取数据?

问题描述:

我的设计文件是这样..如何通过设计文档调用curl请求来获取数据?

{ 
    "_id": "_design/dataFilter", 
    "_rev": "1-29032a3479f5bfb016ea4e2f5e8afae3", 
    "filters": { 
    "getUser": "function (doc, req) { return (req.query.type == doc.type && req.query.id == doc._id) }", 
    "getCustomer": "function (doc, req) { return (req.query.type == doc.type && req.query.id == doc.user) }", 
    "getOrders": "function (doc, req) { return (req.query.type == doc.type && req.query.id == doc.user) }", 
    "getCloths": "function (doc, req) { return (req.query.id == doc._id) }", 
    "getDevices": "function (doc, req) { return (req.query.type == doc.type && req.query.id == doc._id) }" 
    } 
} 

这是我想从CouchDB的获取记录。

curl -X GET http://example.com/database?filter=dataFilter/getCustomer -d '{"query_params":{"id":"jayesh","type":"user"}}' 

如何在设计文档的帮助下从couchdb获取记录?

关于CouchDB中的文档,过滤器只能用于_changes饲料: http://docs.couchdb.org/en/2.0.0/couchapp/ddocs.html#filter-functions

你可以做的,是使用地图的看法是什么/缩小功能: http://docs.couchdb.org/en/2.0.0/couchapp/ddocs.html#view-functions

你只需要emit与过滤器匹配的所有文档。可以根据需要使用emit功能的关键和价值。

在您的例子中,设计文档应该是这样的:

这应该是这样的:该观点已被计算

{ 
    "_id": "_design/dataFilter", 
    "_rev": "1-29032a3479f5bfb016ea4e2f5e8afae3", 
    "views": { 
    "getUser": { 
     "map": "function(doc) { if (req.query.type == doc.type && req.query.id == doc._id) { emit(doc._id, "something") } }" 
    }, 

... 

    } 
} 

后(有什么可以承担大型数据库的一段时间)您可以通过以下方式获取结果:

GET DB/_design/dataFilter/_view/getUser