CouchDB查看多个键值对

时间:2014-06-10 14:50:10

标签: curl couchdb

我是CouchDB的新手,想要为一组文档指定年份范围。每个文档都有一个年份属性。我已将我的观点定义如下:

function(doc) {
    emit(parseInt(doc.year), doc.title);
}

然后我要选择(例如)2000和2005之间制作的电影。据我所知,以下curl命令应该适用于此。

curl http://127.0.0.1:5984/movies/_design/exercises/_view/ex11?startkey=2000&endkey=2005

但是,当我执行此命令时,只有第一个键值对似乎生效(即它只选择2000之后的电影)。如果我改变了startkey和endkey对的顺序,情况也是如此(即它只选择2005年之前的电影)

此外,当我执行上面的curl命令时,似乎程序没有在终端中终止。我必须使用CTRL + C手动终止查询,这在任何其他类型的查询中都不会发生。

每部电影都有以下JSON结构(供您参考):

{
   "_id": "uf",
   "_rev": "1-576d70babcd04fed2918f5c543bb7cf6",
   "title": "Unforgiven",
   "year": "1992",
   "genre": "Western",
   "summary": "The town of Big Whisky is full of normal people trying to lead quiet lives. Cowboys try to make a living. Sheriff 'Little Bill' tries to build a house and keep a heavy-handed order. The town whores just try to get by.Then a couple of cowboys cut up a whore. Unsatisfied with Bill's justice, the prostitutes put a bounty on the cowboys. The bounty attracts a young gun billing himself as 'The Schofield Kid', and aging killer William Munny. Munny reformed for his young wife, and has been raising crops and two children in peace. But his wife is gone. Farm life is hard. And Munny is no good at it. So he calls his old partner Ned, saddles his ornery nag, and rides off to kill one more time, blurring the lines between heroism and villainy, man and myth.",
   "country": "USA",
   "director": {
       "last_name": "Eastwood",
       "first_name": "Clint",
       "birth_date": "1930"
   },
   "actors": [
       {
           "first_name": "Clint",
           "last_name": "Eastwood",
           "birth_date": "1930",
           "role": "William Munny"
       },
       {
           "first_name": "Gene",
           "last_name": "Hackman",
           "birth_date": "1930",
           "role": "Little Bill Dagget"
       },
       {
           "first_name": "Morgan",
           "last_name": "Freeman",
           "birth_date": "1937",
           "role": "Ned Logan"
       }
   ]
}

1 个答案:

答案 0 :(得分:3)

你的观点很好。

&您的curl命令正在被shell解释。将网址放在引号中:

curl "http://127.0.0.1:5984/movies/_design/exercises/_view/ex11?startkey=2000&endkey=2005"