Couch DB - 将输入参数传递给视图

var*_*ani 1 couchdb mapreduce

我正在从我的Web应用程序中将SQL从Cou​​ch DB转移到我的第一个应用程序.

虽然我不能说为什么我不喜欢SQL查询,但不确定我不喜欢,让CURL请求访问我的数据库声音的想法必须比使用PHP PDO更好.

我花了一天半的时间试图熟悉沙发DB HTTP API.我无法声称我已经彻底阅读了API,但是在开始编码之前谁彻底阅读了API.所以我的,可能是愚蠢的问题是 - how do I pass an variable other than doc to a map function while making a http request to the view.API清楚地说地图函数只接受一个"doc"参数,在这种情况下,下面的函数本身是错误的,但我找不到API中允许的任何部分我使用最终用户提供的输入查询数据库.

我的地图功能是

function(doc, pid2){

      if (doc.pid === pid2)
    {
        emit(doc._id, doc) ;

    }
}
Run Code Online (Sandbox Code Playgroud)

pid2是由前端用户提供的号码.

    <?php
    $pid2 = file_get_contents(facebook graphi api call_returns a Profile ID) ;
    $user_exists = HTTP request to couch DB view to return 
in JSON format the list of JSON documents with pid = $pid2
?>
Run Code Online (Sandbox Code Playgroud)

Til*_*del 7

让您的视图doc.pid以键为单位发出文档

function(doc) { 
    emit(doc.pid, doc);
}
Run Code Online (Sandbox Code Playgroud)

并使用该key参数来检索正确的文档:

http://localhost:5984/<database>/_design/<designdoc>/_view/<viewname>?key=<pid2>
Run Code Online (Sandbox Code Playgroud)

这应该返回所有文件doc.pid === pid2.