【发布时间】:2014-12-30 15:51:56
【问题描述】:
我正在从我的 Web 应用程序(我的第一个应用程序)从 SQL 迁移到 Couch DB。
虽然我不能说为什么我不喜欢 SQL 查询,但我不确定我是否不喜欢,但发出 CURL 请求以访问我的数据库的想法肯定比使用 PHPs 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) ;
}
}
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
?>
【问题讨论】: