You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by wh...@aol.com on 2010/08/24 21:14:43 UTC
creating a session then trying to save a doc fails due to authorization
problems
I am using couch.js to get a session. The session is created successfully according to firebug.
Next I want to add a new document to a database I've created
The database is called joe at localhost:5984/joe
joe's login pass is joe:cool
The session command goes through correctly in firebug but just returns json of
{"ok":true,"name":"joe","roles":["user"]}
Next I want to use the following in javascript
mydb = new CouchDB("joe");
mydb.createDb();
doc={"username":"joe","filename":"joesfile","data":"here is joe's data"};
mydb.save(doc);
But this fails due to authorization problems.
Is there something I'm going to need to include in the options in the mydb.save(doc,options)?
The couch.js function is
// Save a document to the database
this.save = function(doc, options) {
if (doc._id == undefined) {
doc._id = CouchDB.newUuids(1)[0];
}
this.last_req = this.request("PUT", this.uri +
encodeURIComponent(doc._id) + encodeOptions(options),
{body: JSON.stringify(doc)});
CouchDB.maybeThrowError(this.last_req);
var result = JSON.parse(this.last_req.responseText);
doc._rev = result.rev;
return result;
}