doc_ids filtering the changes feed on phonegap

177 views
Skip to first unread message

Seung Chan Lim

unread,
May 26, 2014, 9:20:45 PM5/26/14
to mobile-c...@googlegroups.com
Hi all,

I'm making a request to couchbase lite on phonegap to get a continous feed filtered by a doc id. But I'm getting back a 404! 


I've tried not escaping the doc_ids value so it goes in like ["uuid"] but same 404.

If I remove the filter and doc_ids parameter it works fine.

What am I doing wrong?

slim

Seung Chan Lim

unread,
May 26, 2014, 9:33:04 PM5/26/14
to mobile-c...@googlegroups.com
If a 404 means that the id specified in the doc_ids is not an id of any existing doc, is there a way to have it wait until such a document exists and then notify me?

Jens Alfke

unread,
May 27, 2014, 10:29:22 AM5/27/14
to mobile-c...@googlegroups.com

On May 26, 2014, at 6:20 PM, Seung Chan Lim <djs...@gmail.com> wrote:

I'm making a request to couchbase lite on phonegap to get a continous feed filtered by a doc id. But I'm getting back a 404! 

It’s probably telling you it can’t find the filter. The filter name has to be prefixed with the design document name and a slash.

Also, FYI, Couchbase Lite doesn’t support the doc_ids parameter to a _changes request. (It will just ignore it and send you all changes.)

—Jens

Seung Chan Lim

unread,
May 27, 2014, 11:03:20 AM5/27/14
to mobile-c...@googlegroups.com
oh! it's not supported?

But it says it is supported here: 


Am I misreading?

So do I need to create my own view filter to be able to implement such a functionality?

slim

Jens Alfke

unread,
May 27, 2014, 11:24:12 AM5/27/14
to mobile-c...@googlegroups.com, Amy Kurtzman

On May 27, 2014, at 8:03 AM, Seung Chan Lim <djs...@gmail.com> wrote:

But it says it is supported here: 
Am I misreading?

I’m sorry, those docs are wrong — they look like they were based on the CouchDB API documentation, but Couchbase Lite doesn’t support all of those parameters.

Looking at the iOS source, the supported options are: feed, include_docs, style, limit, since, filter
Plus the general options for use with include_docs: attachments, local_seq, conflicts, revs, revs_info

So do I need to create my own view filter to be able to implement such a functionality?

Yeah, it would be easy to write a filter that passed only a set of document IDs specified in a parameter.

—Jens

Seung Chan Lim

unread,
May 29, 2014, 11:25:15 PM5/29/14
to mobile-c...@googlegroups.com, A...@couchbase.com
So I'm trying to resolve this using a custom design doc, I've created a design doc ( _design/_doc_ids ) as follows

{"filters": {"_doc_ids" : "function(doc, req) { if (req.query.doc_ids.indexOf(doc._id) != -1) { return true; } else { return false; } }"}, "roles": ["design document"]}

Jens Alfke

unread,
May 30, 2014, 12:18:32 AM5/30/14
to mobile-c...@googlegroups.com
Underscore prefixes are usually reserved; I don’t know if this will cause trouble in a design document name, but just to be safe, try changing it to “_design/doc_ids” and the filter name to “doc_ids”.

—Jens

Seung Chan Lim

unread,
May 30, 2014, 1:59:10 PM5/30/14
to mobile-c...@googlegroups.com
No dice... This is weird. One oddness I'm seeing is that the design document is oddly displayed in the couchbase web interface. I can see it listed, but when I use the lookup function and type in the id I get "Document does not exist" message. I don't see it under "Views" tab either. But once again, if I use curl to get it, I get it just fine.

I'm putting this design document into couchbase through the sync gateway. I wonder if that's causing trouble?

If I put it directly into couchbase through the web interface I can see it, but then my question is how do you give this new document channel and access?

slim

Seung Chan Lim

unread,
May 30, 2014, 4:22:21 PM5/30/14
to mobile-c...@googlegroups.com
I'm also noticing that the design doc I created through the sync gateway gets replicated to couchbase lite with is id changed to "_design\/name" instead of "_design/name" 

What am I doing wrong?

I'd like to create views on couchbase which then gets replicated out to couchbase lite and used by couchbaselite to do filters on its local couchbase.

slim

J. Chris Anderson

unread,
May 30, 2014, 8:25:41 PM5/30/14
to mobile-c...@googlegroups.com


On Friday, May 30, 2014 1:22:21 PM UTC-7, Seung Chan Lim wrote:
I'm also noticing that the design doc I created through the sync gateway gets replicated to couchbase lite with is id changed to "_design\/name" instead of "_design/name" 

What am I doing wrong?

I'd like to create views on couchbase which then gets replicated out to couchbase lite and used by couchbaselite to do filters on its local couchbase.

slim

On Friday, May 30, 2014 1:59:10 PM UTC-4, Seung Chan Lim wrote:
No dice... This is weird. One oddness I'm seeing is that the design document is oddly displayed in the couchbase web interface. I can see it listed, but when I use the lookup function and type in the id I get "Document does not exist" message. I don't see it under "Views" tab either. But once again, if I use curl to get it, I get it just fine.

I'm putting this design document into couchbase through the sync gateway. I wonder if that's causing trouble?


The sync gateway doesn't support design document replication for now. You can write the contents of the design document to a regular document and then rename it on the client to install it.

Patches welcome!

Chris

Seung Chan Lim

unread,
May 30, 2014, 9:04:49 PM5/30/14
to mobile-c...@googlegroups.com
Ha.... Interesting. Is that at all illegal from the app store perspective?

slim

J. Chris Anderson

unread,
May 30, 2014, 11:17:27 PM5/30/14
to mobile-c...@googlegroups.com


On Friday, May 30, 2014 6:04:49 PM UTC-7, Seung Chan Lim wrote:
Ha.... Interesting. Is that at all illegal from the app store perspective?

It's been a while since I read it but we wouldn't be the first downloading JavaScript code, I think a lot of PhoneGap apps are just wrappers around web views pointed at remote servers.

Chris 

Seung Chan Lim

unread,
May 31, 2014, 1:16:55 AM5/31/14
to mobile-c...@googlegroups.com
Still not working. Getting a 404. Totally stumped...

Came across this

https://groups.google.com/forum/#!searchin/mobile-couchbase/_design%5C$2F/mobile-couchbase/MhLTBTUUhxw/_RCu8g2OVGEJ

Is it an issue with me building couchbase? Do I need to do something special to make design docs work on phonegap via js?

This is where I'm getting couchbase lite to build along with steroids.


slim

J. Chris Anderson

unread,
May 31, 2014, 8:41:45 AM5/31/14
to mobile-c...@googlegroups.com
Here's an example of setting up views from inside the PhoneGap runtime.


Have you been able to get this to run by following the getting started guide? http://developer.couchbase.com/mobile/get-started/get-started-mobile/phonegap/index.html

Seung Chan Lim

unread,
Jun 1, 2014, 8:36:06 PM6/1/14
to mobile-c...@googlegroups.com
The view works just fine. It's the filters that don't seem to work.

Do you have examples of using filters with _changes request to local couchbase mobile?

slim

Jens Alfke

unread,
Jun 3, 2014, 11:37:49 PM6/3/14
to mobile-c...@googlegroups.com

On May 30, 2014, at 8:17 PM, J. Chris Anderson <jch...@couchbase.com> wrote:

Ha.... Interesting. Is that at all illegal from the app store perspective?

It's been a while since I read it but we wouldn't be the first downloading JavaScript code, I think a lot of PhoneGap apps are just wrappers around web views pointed at remote servers.

That specific usage is OK. Apple specifically allows UIWebViews to download and run JavaScript; otherwise UIWebView wouldn’t be able to render any real-world web pages, after all. And the JS is sandboxed by the view.

But Apple does not allow any other execution of downloaded code of any sort, including JS with JavaScriptCore. Replicating a design document from a server and then running a filter or map function from it would definitely be illegal and liable to get your app rejected.

—Jens

Seung Chan Lim

unread,
Jun 4, 2014, 12:58:42 AM6/4/14
to mobile-c...@googlegroups.com
Wait, I'm confused. You're saying replicating a design document and running a filter or a map function from it would be illegal. What are you then referring to when you say "That specific usage is OK"? The usage being discussed is replicating a document then renaming it as a design doc on the local couchbase lite and running the filter or map function. Aren't the two cases the same?

Jens Alfke

unread,
Jun 4, 2014, 1:14:11 AM6/4/14
to mobile-c...@googlegroups.com
On Jun 3, 2014, at 9:58 PM, Seung Chan Lim <djs...@gmail.com> wrote:

Wait, I'm confused. You're saying replicating a design document and running a filter or a map function from it would be illegal.

Yes.

What are you then referring to when you say "That specific usage is OK”?

A PhoneGap app running web pages (HTML + JS + images + …) downloaded from a website. The difference is that the JS is run inside a UIWebView, which is explicitly allowed.

—Jens

Seung Chan Lim

unread,
Jun 4, 2014, 11:51:51 AM6/4/14
to mobile-c...@googlegroups.com
Oh, I see. So what Chris is suggesting _is_ illegal. Am I understanding you?

slim

Jens Alfke

unread,
Jun 6, 2014, 6:27:46 PM6/6/14
to mobile-c...@googlegroups.com

On Jun 4, 2014, at 8:51 AM, Seung Chan Lim <djs...@gmail.com> wrote:

Oh, I see. So what Chris is suggesting _is_ illegal. Am I understanding you?

Yes, my understanding is that it’s illegal to download a design doc from a server if it contains JS code that will be run on the client.

—Jens

J. Chris Anderson

unread,
Jun 7, 2014, 8:28:27 AM6/7/14
to mobile-c...@googlegroups.com


On Friday, June 6, 2014 3:27:46 PM UTC-7, Jens Alfke wrote:

On Jun 4, 2014, at 8:51 AM, Seung Chan Lim wrote:

Oh, I see. So what Chris is suggesting _is_ illegal. Am I understanding you?

Yes, my understanding is that it’s illegal to download a design doc from a server if it contains JS code that will be run on the client.

I'm no lawyer but I wonder if it's changed now that JavaScriptCore is public. Stackoverflow has a lively debate. The best suggestion in that thread is to talk to Apple Developer Relations and ask. 

The PhoneGap Developer App is also inspiring. Although I bet it sticks to UIWebView APIs.

Chris

Jens Alfke

unread,
Jun 7, 2014, 5:35:12 PM6/7/14
to mobile-c...@googlegroups.com

On Jun 7, 2014, at 5:28 AM, J. Chris Anderson <jch...@couchbase.com> wrote:

I'm no lawyer but I wonder if it's changed now that JavaScriptCore is public. Stackoverflow has a lively debate. The best suggestion in that thread is to talk to Apple Developer Relations and ask. 

I’m no lawyer either, but I don’t think this changes anything. The rules say:

3.3.2 An Application may not download or install executable code. Interpreted code may only be used in an Application if all scripts, code and interpreters are packaged in the Application and not downloaded. The only exception to the foregoing is scripts and code downloaded and run by Apple's builtin WebKit framework…

JavaScriptCore is not WebKit; it’s a lower-level framework that’s used by WebKit. Also, it specifies that the JS also has to be downloaded by WebKit, which is not the case with CBL; the replicator uses NSURLConnection, which again is a lower-level API.

If your iOS app really, really has to replicate design documents, PouchDB is an alternative that would play by Apple’s rules.

—Jens
Reply all
Reply to author
Forward
0 new messages