How to get "_changes" from phonegap app

40 views
Skip to first unread message

Federico Hernandez

unread,
Jan 8, 2015, 2:46:48 PM1/8/15
to mobile-c...@googlegroups.com
Hi everybody,

I've implemented the sync process based on a coubchbase app developed with phonegap. However, I have some issues when I try to get the changes from the SG. 

This is what I did. I created two documents and a user. The app sent the changes to the SG and then to the couchbase server. After that, I removed the app from the phone, installed it again and stopped the SG. When the app started up again, I could see in the SG logs the changes coming from the couchbase server to the SG. The problem came up when the app tried to get the changes from the SG. If I try to see them through the admin interface (SG) I can see them well. However, if I try to get them from the mobile app, I only get one of them, the one related to the user document.

Here I copy the logs from SG:

[I think the following is from the sync process between couchbase and sync gateway]

15:11:28.786582 HTTP:  #012: GET /adb/_changes?feed=longpoll&heartbeat=1000&style=all_docs&since=0&limit=100&include_docs=true  (ADMIN)
2015/01/08 15:11:29 go-couchbase: call to ViewCustom("sync_gateway", "channels") in github.com/couchbaselabs/sync_gateway/base.couchbaseBucket.ViewCustom took 243.772833ms
15:11:29.030749 changes_view: Query took 243.893437ms to return 2 rows, options = db.Body{"limit":100, "stale":false, "startkey":[]interface {}{"*", 0x1}, "endkey":[]interface {}{"*", 0x4}}
15:11:29.035647 WARNING: Changes feed: error getting doc "_user/fede": 400 Invalid doc ID -- db.(*Database).addDocToChangeEntry() at changes.go:57
15:11:29.035713 HTTP+: #012:     --> 200 OK  (0.0 ms)

[The following shows the changes retrieved through the admin interface]

15:44:22.054865 HTTP:  #038: GET /vdb/_changes?feed=longpoll&heartbeat=1000&style=all_docs&since=0&limit=100&include_docs=true  (ADMIN)
15:44:22.138401 WARNING: Changes feed: error getting doc "_user/fede": 400 Invalid doc ID -- db.(*Database).addDocToChangeEntry() at changes.go:57
15:44:22.138459 HTTP+: #038:     --> 200 OK  (0.0 ms)

[browser's console output]

{
results: [
  {
    seq: 2,
    id: "B14D6B41-DB44-404E-A355-43DDB252A81E",
    doc: {
      _id: "B14D6B41-DB44-404E-A355-43DDB252A81E",
      _rev: "1-0c0ff608417c7a4748215a822b61d2ae",
      active: true,
      createdAt: "2015-01-08T15:19:24.629Z",
      id: "record-158",
      modifiedAt: "2015-01-08T15:19:24.629Z",
      name: "Thu Jan 08 2015 12:19:20",
  type: "event"
    },
    changes: [
     {
     rev: "1-0c0ff608417c7a4748215a822b61d2ae"
     }
    ]
  },
  {
    seq: 3,
    id: "C4315EBA-1C17-4136-AECE-0D1AF33C10BE",
    doc: {
      _id: "C4315EBA-1C17-4136-AECE-0D1AF33C10BE",
      _rev: "1-f2fc940cb0aab6289228e1ef9884ab3f",
      active: true,
      createdAt: "2015-01-08T15:19:42.406Z",
      id: "record-161",
      modifiedAt: "2015-01-08T15:19:42.406Z",
      name: "Thu Jan 08 2015 12:19:40",
      type: "event"
    },
    changes: [
      {
      rev: "1-f2fc940cb0aab6289228e1ef9884ab3f"
      }
    ]
  },
  {
    seq: 4,
    id: "_user/fede",
    changes: [
      {
        rev: ""
      }
    ]
  }
  ],
  last_seq: "4"
}

[The following shows the changes retrieved from the my app]

15:18:52.892483 HTTP:  #020: GET /adb/_changes?feed=longpoll&include_docs=true&conflicts=true&style=all_docs&since=1&limit=100
15:18:52.892575 HTTP: #020:     --> 401 Login required  (2.3 ms)
15:18:53.495125 HTTP:  #021: GET /adb/_changes?feed=longpoll&include_docs=true&conflicts=true&style=all_docs&since=1&limit=100  (as fede)
15:18:53.495422 WARNING: Changes feed: error getting doc "_user/fede": 400 Invalid doc ID -- db.(*Database).addDocToChangeEntry() at changes.go:57
15:18:53.495822 HTTP+: #021:     --> 200 OK  (0.0 ms)

[browser's console output]

{"results":[{"seq":4,"id":"_user/fede","changes":[]}],"last_seq":"4"}

As it can be seen, the changes attribute is an empty array here. Could anybody tell me why is that and how could I get the same changes that I get through the admin interface? Why are there two HTTP requests to get the changes if the app only makes one?

Thanks in advance,

Jens Alfke

unread,
Jan 8, 2015, 2:51:08 PM1/8/15
to mobile-c...@googlegroups.com
If you can see the docs in the _changes output on the admin interface, but they don't replicate to the app, then the problem is probably with access privileges. Make sure the user account the app logs in as has access to at least one of the channels the docs are assigned to by the sync function.

—Jens

Federico Hernandez

unread,
Jan 8, 2015, 2:54:23 PM1/8/15
to mobile-c...@googlegroups.com

On Thursday, January 8, 2015 4:51:08 PM UTC-3, Jens Alfke wrote:
If you can see the docs in the _changes output on the admin interface, but they don't replicate to the app, then the problem is probably with access privileges. Make sure the user account the app logs in as has access to at least one of the channels the docs are assigned to by the sync function.

I'm using the following sync function:

function (doc) {
  channel(doc.channels);
}
 
I created the user as following:

curl -X PUT http://localhost:4985/adb/_user/fede --data \ '{"name": "fede", "email":"some...@domain.com", "channels":["*"], "role":"user", "password": "******"}'

 

Traun Leyden

unread,
Jan 8, 2015, 4:11:33 PM1/8/15
to mobile-c...@googlegroups.com
I think you want to use admin_channels instead of channels, ie:

curl -X PUT http://localhost:4985/adb/_user/fede --data \ '{"name": "fede", "email":"some...@domain.com", "admin_channels":["*"], "role":"user", "password": "******"}'

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/421ca1a7-63a7-4c3d-b000-a9dd364da55a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Federico Hernandez

unread,
Jan 8, 2015, 4:23:07 PM1/8/15
to mobile-c...@googlegroups.com


On Thursday, January 8, 2015 at 6:11:33 PM UTC-3, Traun Leyden wrote:
I think you want to use admin_channels instead of channels, ie:

curl -X PUT http://localhost:4985/adb/_user/fede --data \ '{"name": "fede", "email":"some...@domain.com", "admin_channels":["*"], "role":"user", "password": "******"}'

Thank you Jens, the was related to the access privileges because I have used a wrong attribute in the SG config file.
Thank you Traun, you were right, the problem was in the attribute name.
Reply all
Reply to author
Forward
0 new messages