使用 key、startkey 时,CouchDB 视图抛出无效的 UTF-8 JSON 错误
我在 CouchDB 中定义了一个非常基本的视图:
function(doc) {
if(doc.date && doc.erc) {
emit(doc.date, doc.erc);
}
}
它只是提取所有文档并按日期排序。
我尝试附加
?startkey="2010-05-01"
到 URL 和 Futon 只是浏览器重定向。
我也尝试过使用 CURL:
curl -X GET http://localhost:5984/plots/_design/by_date/_view/by_date?startkey="2010-05-01"
这会引发错误:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}
我做错了什么?这应该是一个非常基本的事情。
谢谢, -吉姆
I have a VERY basic view defined in CouchDB:
function(doc) {
if(doc.date && doc.erc) {
emit(doc.date, doc.erc);
}
}
It simply pulls ALL documents and sorts by dates.
I've tried appending
?startkey="2010-05-01"
to the URL and Futon just browser redirects.
I've tried using CURL as well:
curl -X GET http://localhost:5984/plots/_design/by_date/_view/by_date?startkey="2010-05-01"
That throws an error:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}
What am I doing wrong? This should be a VERY basic thing.
Thanks,
-Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
CouchDB 需要查看双引号。
Bash 可能会在
curl
运行之前吃掉你的双引号。将 URL(双引号和全部)放在单引号中。这样,Bash 会将引号发送到
curl
,curl 会将它们发送到 CouchDB。可能 Firefox 或 Futon 也在吃掉你的报价。蒲团的右上角有一个灰色的指针图标。它链接到视图的原始 URL。尝试在其中添加
startkey
。您还可以将双引号输入为%22
。CouchDB needs to see the double-quotes.
Bash is probably eating your double quotes before
curl
runs. Put the URL (double-quotes and all) in single quotes.That way, Bash will send the quotes to
curl
which will send them to CouchDB.Possibly Firefox or Futon is eating your quotes too. Futon has a gray pointer icon in the upper-right. That links to the raw URL of the view. Try adding the
startkey
there. You can also input the double-quotes as%22
.我不知道你是否已经找到了解决方案..无论如何,对于像我这样遇到同样错误的观众来说。这就是解决办法。我在 Windows 中尝试过
I dont know whether you have already got the solution.. anyway for viewers like me who got the same error. This is the solution . I tried in windows
这在 cygwin 中对我有用
This works for me in cygwin
您还可以使用 URL
%codes
,大多数 fetch 程序会将%22
转换为双引号"
You can also use URL
%codes
,%22
gets converted to double quotes"
by most fetch programs