我正在使用php- on -couch库从couchdb检索数据,我想基于where条件检索数据。我想要根据用户谁是登录的数据。下面的代码检索一个名为accounts的视图,但我希望检索时不在couchdb上创建视图。任何帮助都是非常感谢的
try {
$doc = $client->asArray()->getView('accounts', 'accounts');
} catch (Exception $e) {
if ($e->code() == 404) {
echo "View not found\n";
} else {
echo "Error: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
}
exit(1);
}
print_r($doc);
有没有更好的方法来像mysql一样动态创建检索视图?
发布于 2017-09-07 18:11:38
使用php-on-couch可以做到这一点
try {
$opts = array("include_docs" => true, "key" => "your user name");
$doc = $client->setQueryParameters($opts)->getView("accounts", "accounts");
} catch (Exception $e) {
if ($e->code() == 404) {
echo "Account not found\n";
} else {
echo "Error: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
}
exit(1);
}
print_r($doc);
确保在accounts视图中发出用户名作为键。Couch db将在视图中搜索所有帐户,并给出包含您用户名的文档。
emit(doc.username, doc);
希望它能帮助您在php中使用couchdb
https://stackoverflow.com/questions/46089085
复制相似问题