ouchdb查询具有关键参数的视图 [英] couchdb query a view with key parameters
问题描述
没有关键参数,视图可以正常工作
Without a key parameter, the view works correctly
$curl "http://127.0.0.1:5984/music/_design/albums/_view/by_release_date"
{"total_rows":311,"offset":0,"rows":[
{"id":"a4327d0718d3b1e227df7124a99a7fc3","key":"1991-12-22","value":{"by":"张楚","title":"黑月亮"}},
{"id":"a4327d0718d3b1e227df7124a99a3ac5","key":"unknown","value":{"by":"郑钧","title":"郑钧:赤裸裸"}},
但是当使用键时,我得到了错误的请求响应或空的结果.为什么?
but when with a key, i got either bad request response or empty result. Why?
$curl "http://127.0.0.1:5984/music/_design/albums/_view/by_release_date?key=unknown"
{错误":"bad_request",原因":"invalid_json"}
$curl "http://127.0.0.1:5984/music/_design/albums/_view/by_release_date?key=unknown"
{"error":"bad_request","reason":"invalid_json"}
$curl "http://127.0.0.1:5984/music/_design/albums/_view/by_release_date?key=1993"
{"total_rows":311,偏移量":0,行":[
$curl "http://127.0.0.1:5984/music/_design/albums/_view/by_release_date?key=1993"
{"total_rows":311,"offset":0,"rows":[
]}
地图功能是:
map
function(doc) {
key = doc.release_date
value = {by: doc.author , title: doc.title}
emit(key, value);
}
推荐答案
密钥是字符串,因此您需要包含"
= %22
,例如http://127.0.0.1:5984/music/_design/albums/_view/by_release_date?key=%221993%22
The key is a string hence you need to include "
= %22
, e.g http://127.0.0.1:5984/music/_design/albums/_view/by_release_date?key=%221993%22
这篇关于ouchdb查询具有关键参数的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!