运行CouchRest.put()时出错

时间:2011-12-17 03:34:29

标签: ruby couchdb

当我尝试在irb

中运行命令时,我需要更新couchdb文档
  CouchRest.put('http://localhost:5984/db', {"_id": "1","_rev": "sdf", "test": "testing"})

我收到错误 -

RestClient :: Request :: Unauthorized:401 Unauthorized:{“error”:“unauthorized”,“reason”:“你不是服务器管理员。”}

在同一个控制台中,我能够成功运行 -

  CouchRest.post('http://localhost:5984/db', {"test": "testing"})

请有人帮忙解决这个问题。

干杯!

1 个答案:

答案 0 :(得分:3)

这个很简单。 API声明针对db名称的PUT(在您的示例中为“db”)尝试创建新数据库,这需要管理员权限。

要创建新文档,您可以成功使用POST,但API文档不鼓励使用POST。 PUT可用于创建和更新。

要更新现有文档,请使用带有URL路径中文档ID的PUT以及要在JSON中更新的所需修订;例如,CouchRest.put('http://localhost:5984/db/1', {"rev": "sdf", "test": "testing"})

有关详情,请参阅Apache's Document API doc in the Wiki上的API文档。