2014-06-10 69 views
2

我是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" 
     } 
    ] 
} 

回答

3

你的觀點是好的。

您的curl命令中的&正被您的shell解釋。將網址放在引號中:

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