【问题标题】:CouchDB error using startkey&endkey in a key array在键数组中使用 startkey 和 endkey 时出现 CouchDB 错误
【发布时间】:2016-07-08 09:50:55
【问题描述】:

大家好,我正在尝试使用以下请求:

curl http://localhost:5984/contacts/_design/country/_view/USA?startkey=["USA",{}]&endkey=["USA",{}]。

关于以下观点:

{
"_id": "_design/country",
"_rev": "1-51488ea3931fdca9b9e2de84ef99c4d9",
"language": "javascript",
"views": {
   "USA": {
       "map": "function(doc) {\nif(doc.type == \"contact\") \nemit([doc.country,doc.name] , {name: doc.name, email: doc.email});\n}\n"
   }
 }
 }

我收到此错误:[globbing] 第 72 列中的错误范围

你能帮帮我吗?

【问题讨论】:

  • 您应该只为endkey 包含,{},将其排除在startkey 之外。此外,我会将您的 URL 用单引号括起来,这样您的 shell 就不会尝试将 {} 扩展为 glob 模式。 (或尝试亚历克西斯关于添加-g 的回答)
  • 与startkey="USA" 相比,startkey=["USA",{}] 做了什么?
  • 我将 ,{} 离开了启动键,但我得到了同样的错误。如果我使用 startkey="USA" 我得到 {"error":"bad_request","re​​ason":"invalid_json"}。

标签: javascript view couchdb


【解决方案1】:

我想问题来自 cUrl 吗?试试这个:

-g/--globoff
              This  option  switches  off  the "URL globbing parser". When you set this option, you can
              specify URLs that contain the letters {}[] without having them being interpreted by  curl
              itself.  Note  that  these  letters  are not normal legal URL contents but they should be
              encoded according to the URI standard.

【讨论】:

  • 你试过 Dominic Barnes 评论吗?
  • 是的,我做到了。使用 startkey=%22USA%22?endkey... 之类的东西怎么样?
【解决方案2】:

只需对括号进行编码,这样 curl 就不会抱怨。 而且您可能希望使用不同的启动键(不带大括号),否则您将不会得到任何结果。正确的行:

curl http://localhost:5984/contacts/_design/country/_view/USA?startkey=%5B"USA"%5D&endkey=%5B"USA",%7B%7D%5D

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    相关资源
    最近更新 更多