Admin REST API GET error when using this config

I’ve just updated my sync gateway config to - https://gist.github.com/derekdon/b08b4eec2dd8b1730ebd

I can create docs using the Admin REST api, but when I try to get them I’m seeing -
body { error: ‘not_found’, reason: ‘Not imported’ }. I’m not using bucket shadowing by the way, this is a brand new DB.

I wasn’t having this problem before I scrapped the last DB and recreated one using the above config. The old config was just the typical TODO one as I was only testing, and everything used to work fine… granted the docs I was posting and getting didn’t have list/task or channel props.

Reading Using admin REST API on sync gateway has answered some of my questions, but I was wondering if there is something in my sync function that’s causing this. Is it the fact that the document I’ve created has a channels array but it’s currently only setup for the future user (currently guest). Are GET’s on the admin API subject to being restricted by channels? Should these calls on the admin port be able to retrieve all channels?

Hello @derekdon,

Can you post also the document you are testing against the sync-function in question?

As long as users are authenticated, they will be subscribed to the channel and have access.

Hey @sweetiewill, thanks for the response. Sure I understand how that works with actual _users. The question relates to using the ADMIN port to GET a document I’ve just successfully POST’ed using it. A document during during registration might look like this:

    {
        _id: 'profile:some@unverified_email_address.com',
        jsonType: 'profile',
        owner: 'some@unverified_email_address.com',
        emailAddresses: [
            {
                label: 'Primary',
                value: 'some@unverified_email_address.com',
                primary: 1,
                verified: 0,
                verificationCode: 123456
            }
        ],
        channels: ['some@unverified_email_address.com'],
        flags: {
            registered: 0
        }
    }

Later this will be migrated to an actual profile.

The old sync function was just pulled from a sample todo project, however with it I never had a problem. It looked like this:

    function(doc, oldDoc) {
        // NOTE this function is the same across the iOS, Android, and PhoneGap versions.
        if (doc.type == "task") {
            if (!doc.list_id) {
                throw({forbidden : "items must have a list_id"})
            }
            channel("list-"+doc.list_id);
        } else if (doc.type == "list") {
            channel("list-"+doc._id);
            if (!doc.owner) {
                throw({forbidden : "list must have an owner"})
            }
            if (oldDoc) {
                var oldOwnerName = oldDoc.owner.substring(oldDoc.owner.indexOf(":")+1);
                requireUser(oldOwnerName)
            }
            var ownerName = doc.owner.substring(doc.owner.indexOf(":")+1);
            access(ownerName, "list-"+doc._id);
            if (Array.isArray(doc.members)) {
                var memberNames = [];
                for (var i = doc.members.length - 1; i >= 0; i--) {
                    memberNames.push(doc.members[i].substring(doc.members[i].indexOf(":")+1))
                };
                access(memberNames, "list-"+doc._id);
            }
        } else if (doc.type == "profile") {
            channel("profiles");
            var user = doc._id.substring(doc._id.indexOf(":")+1);
            if (user !== doc.user_id) {
                throw({forbidden : "profile user_id must match docid"})
            }
            requireUser(user);
            access(user, "profiles"); // TODO this should use roles
        }
    }

The ‘not imported’ error on a GET should only occur when that document has invalid sync metadata. Normally that shouldn’t be possible for documents created through Sync Gateway’s REST API.

I don’t see anything obvious in your sync function or document body that would cause this - it might help to take a look at the doc through the Couchbase Server admin UI to see what it looks like. Also, what Sync Gateway build are you running?

Hey thanks for clarifying, good to know. Well good news… I rebuilt the cluster and it’s working as expected! I think there must have been something left over in the /opt/var/couchbase after the last update of the config, so I cleared that out on this attempt.

fleetctl list-machines | grep -v MACHINE | awk '{print $2}' | xargs -I{} ssh {} 'sudo rm -rf /opt/couchbase/var/'

Using https://github.com/tleyden/couchbase-cluster-go by the way.

The issue was making me question everything I thought I knew about using the admin port. Thanks for your input guys.