2017-03-31 15 views
0

私の設計文書は、このような何か..です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のからレコードを取得しようとしています方法です。

私はどのように設計ドキュメントの助けを借りてcouchdbからレコードを取得できますか? CouchDBののドキュメントについては、フィルタが_changes飼料用にのみ使用することができ

答えて

0

:あなたは何ができるか 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関数のキーと値は、必要に応じて使用できます。

あなたの例では、設計-docのは、次のようになります。

これは次のようになります。ビューは、(大きなデータベースに多少時間がかかることができるもの)が計算された後

{ 
    "_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

関連する問題