Confused over sync config, why all_docs returns nothing?

380 views
Skip to first unread message

James

unread,
Mar 29, 2014, 9:44:58 AM3/29/14
to mobile-c...@googlegroups.com
Hi,

I'm having some trouble configuring the sync gateway, having pieced together examples from grocery-sync and the documentation.

I have setup a bucket named aussie-coins-bucket on my couchbase server, with the following document inserted with id of 1

{
  "coin": "One Cent",
  "type": {
    "typeName": "Type 1",
    "years": "1966 - 2006"
  },
  "Reverse Designer": "Stuart Devlin",
  "Obverse Designer": "Arnold Machin",
  "Weight": "2.59 grams",
  "Size": "17.53 mm",
  "Composition": {
    "Copper": "97%",
    "Zinc": "2.5%",
    "Nickel": "0.5%"
  }
}

I am using the following config for sync-gateway

{
    "interface": ":4984",
    "adminInterface": ":4985",
    "log": ["CRUD", "CRUD+", "HTTP", "HTTP+", "Access", "Cache", "Shadow", "Shadow+", "Changes", "Changes+"],
    "databases": {
        "aussie-coins-syncdb": {
            "server": "http://localhost:8091",
            "bucket": "aussie-coins-bucket",
            "sync": `function(doc) {channel(doc.channels);}`,
            "users": {
                "GUEST": {
                    "disabled": false,
                    "admin_channels": ["*"]
                }
            }
        }
    }
}

When I try a GET on http://localhost:4984/aussie-coins-syncdb/_all_docs I get the following response:

{
    "rows": [],
    "total_rows": 0
}

I was expecting to see the document here, why does the response show there are no rows? This is the sync gateway output

13:29:19.165477 HTTP:  #004: GET /aussie-coins-syncdb/_all_docs

What have I misconfigured? 

I'm running Couchbase Version: 2.2.0 community edition (build-837) and sync-gateway-1.0-beta2

Jens Alfke

unread,
Mar 29, 2014, 11:31:01 AM3/29/14
to mobile-c...@googlegroups.com

On Mar 29, 2014, at 6:44 AM, James <james...@gmail.com> wrote:

I have setup a bucket named aussie-coins-bucket on my couchbase server, with the following document inserted with id of 1

How did you add the document? The bucket the gateway is using is private to the gateway; you can’t modify it using Couchbase Server APIs. You need to go through the gateway’s REST API. Or you can tell the gateway to “shadow” another bucket on the server, and you can make changes to that bucket.

—Jens

James

unread,
Mar 29, 2014, 6:56:42 PM3/29/14
to mobile-c...@googlegroups.com
I added the document via the couchbase server, not via the sync gateway.

Out of interest, why does the sync gateway have to use a private bucket and not an existing bucket?

Forgive the noob questions, I'm new to couchbase and am evaluating it as a means for exposing data from a web application out to mobile devices. As an R&D project, I have a web application that administers data on coin collections stored in a couchbase server, and I want this information to be pushed out to a mobile app so they have the latest coin information. 

Perhaps shadowing will do what I need, or is couchbase/sync not a good fit for this?

Jens Alfke

unread,
Mar 29, 2014, 7:58:06 PM3/29/14
to mobile-c...@googlegroups.com
On Mar 29, 2014, at 3:56 PM, James <james...@gmail.com> wrote:

I added the document via the couchbase server, not via the sync gateway.

We need to do something in our docs to make it really clear that this isn’t legal. So many people are doing this.

Out of interest, why does the sync gateway have to use a private bucket and not an existing bucket?

Because the docs the gateway stores have a bunch of metadata added to them that’s crucial for replication and channel assignment. If you make changes to such a document, you either remove that metadata (bad, because the gateway loses its knowledge of the doc’s channels and replication state) or you keep the old metadata (also bad, because the metadata should have been updated to reflect the new revision but wasn’t, so now sync will be screwed up, also the channels might have changed.)

We tried to find ways to make this work, but it’s not feasible without adding features to Couchbase Server itself to let the gateway intercept such changes, and the schedules of the products didn’t make that possible for 1.0.

There is a config flag you can set that will make the gateway detect new docs added by another app and add the metadata to them. I don’t think it’s a good solution, though, because it only works for adding new docs, not updating existing ones.

Bucket shadowing is a better approach. By keeping your changes in a separate bucket, the gateway can watch them and update its own copies of them properly.

Another approach is for your server-side code to write documents directly to the gateway’s REST API instead of to Couchbase Server. The gateway supports a large subset of CouchDB’s API.

—Jens

James

unread,
Apr 2, 2014, 1:45:18 PM4/2/14
to mobile-c...@googlegroups.com
Thanks Jens,

I spoke to Wayne at Couchbase Live London and bucket shadowing seems to be the preferred option.

For anyone else landing on this thread, this link will help you:

Thanks

Алексей Щ.

unread,
Sep 8, 2014, 10:46:45 AM9/8/14
to mobile-c...@googlegroups.com
Hello Jens!
Please, do it ASAP
I spent all my day being figuring out what really happened. I think many people just do manual testing of the db for the first time and there is obviously lack of documentation here.
Thank you!
Reply all
Reply to author
Forward
0 new messages