Reputation: 3341
I need to update a couchdb document, when i try and run the command in irb
CouchRest.put('http://localhost:5984/db', {"_id": "1","_rev": "sdf", "test": "testing"})
I get an error -
RestClient::Request::Unauthorized: 401 Unauthorized: {"error":"unauthorized","reason":"You are not a server admin."}
While in the same console, I am able to successfully run -
CouchRest.post('http://localhost:5984/db', {"test": "testing"})
Could somebody help with this please.
Cheers!
Upvotes: 1
Views: 409
Reputation: 306
This one is straightforward. The API states that a PUT against the name of a db (in your example, "db") attempts to create a new database, which requires admin privileges.
To create a new document, you may use a POST as you did successfully, but the API documents discourage the use of POSTs. PUTs can be used for both creates and updates.
To update an existing document, use a PUT with the ID of the document in the path of the URL and the desired revision to update in the JSON; e.g., CouchRest.put('http://localhost:5984/db/1', {"rev": "sdf", "test": "testing"})
For more information, see the API documentation at Apache's Document API doc in the Wiki.
Upvotes: 3