Trevor
Trevor

Reputation: 2922

Looking for direction on a pouchdb error

error:"unauthorized"
id:"_design/db"
message:"You are not a db or server admin."
name:"unauthorized"
ok:true
reason:"You are not a db or server admin."
rev:"137-81fe83389359c1cfb50bf928f3558b81"
status:500

Pouchdb is trying to push a design document, after a full uninstall/reinstall of the app (so the local pouchdb should have been erased). I am guessing this is in the change stream somewhere. But the weird part is the couchdb is on revision 133, not 137.

How do I fix this? I tried a compact but that didn't work. Only obvious answer I can think of is manually make a bunch of revisions to the design on couch, so that it's newer than 137.

I ran a search on the changes stream using this code

var http=require('http');
var url = "http:/server/db/_changes?style=all_docs";
http.get(url, function(res){
    var body = '';

    res.on('data', function(chunk){
        body += chunk;
    });

    res.on('end', function(){
        var test = JSON.parse(body);
        test.results.forEach(function(item,index){
            if (item.id==="_design/db"){
                console.log(item);
            }
        });
    });
}).on('error', function(e){
    console.log("Got an error: ", e);
});

And got 1 result, rev 133, the correct one. So where is pouchdb getting this from?

--Edit Deleting the pouch database seems to fix it until the next app install.

Upvotes: 0

Views: 306

Answers (2)

Trevor
Trevor

Reputation: 2922

So it turns out Android now uses google drive to make backups of indexdb. This was causing the installed version of the app to keep getting a future version of the document after database rollbacks during testing. The only way around it I found was to do this.

.on('denied', function (result) {
    if (result.doc.error === "unauthorized" && result.doc.id === "_design/db") {
        //catastrophic failure
        var DBDeleteRequest = window.indexedDB.deleteDatabase("_pouch_");

        DBDeleteRequest.onerror = function (event) {
            console.error("Error deleting database.");
            throw new Error("Error deleting database.");
        };

        DBDeleteRequest.onsuccess = function (event) {
            console.log("Database deleted successfully");
            window.location.reload(); //reload the app after purge
        };
    }
}

Even a pouchdb.destroy would not fully clear the problem. It's a bit of a nuke from orbit solution.

Upvotes: 0

Megidd
Megidd

Reputation: 7938

The error status code is 500 which based on the documentation is:

500 - Internal Server Error

The request was invalid, either because the supplied JSON was invalid, or invalid information was supplied as part of the request.

Also, the error message and reason mention that:

message:"You are not a db or server admin."

reason:"You are not a db or server admin."


I think the error might be caused by database admin and member permissions. Because, ordinary database member users/roles cannot PUT design docs, only database admin users/roles can PUT design docs:

enter image description here


You mentioned that:

It's really just because the phone has some future version of the design doc ...

If there is a problem with revision, there should be received a 409 - Conflict error NOT a 500 - Internal Server Error.


I'm not sure, just an idea.

Upvotes: 1

Related Questions