Can't create local Db w/CBLite/Phonegap/AngularJS

276 views
Skip to first unread message

pjac...@surgeforward.com

unread,
Sep 30, 2014, 1:54:17 PM9/30/14
to mobile-c...@googlegroups.com
We are only using Couchbase as a local data store (for now), no sync gateway. I've got things to the point where I can get a response from the local server on both Android and iOS (that's all we're supporting now). Both seem to return different values for URL, which is fine, but I'm not able to create a database or documents. The response is correctly returning info that there is no database value when I request.

On iOS the servername is "http://lite.couchbase./" and on Android it's "http://some-long-uuid-13245@localhost:5964"

I've tried all kinds of different servername urls but no luck so far. It seems like I must be missing something obvious but this use case seems pretty non-standard so haven't had much luck searching documentation (though I have).

sometimes I seem to get a "no auth" response but I don't need/haven't set up any auth since it's local to device.

Yes, I have read the docs and the REST API etc.

pjac...@surgeforward.com

unread,
Oct 1, 2014, 4:57:10 PM10/1/14
to mobile-c...@googlegroups.com
Specific error messages:

iOS:

A PUT request for this:


returns

[Error] Failed to load resource: the server responded with a status of 400 (Bad Request) (workMax, line 0)
{"status":400,"error":"Invalid database\/document\/revision ID"}

Jens Alfke

unread,
Oct 1, 2014, 5:14:06 PM10/1/14
to mobile-c...@googlegroups.com

On Oct 1, 2014, at 1:57 PM, pjac...@surgeforward.com wrote:

[Error] Failed to load resource: the server responded with a status of 400 (Bad Request) (workMax, line 0)
{"status":400,"error":"Invalid database\/document\/revision ID"}

That means what it says: "Invalid database … ID". Database names can't contain capital letters (for compatibility with CouchDB.) The API docs for the Database class specify the character set, if you're curious; personally I stick to lowercase alphanumerics, hyphens and underscores.

—Jens

Peter Jacobson

unread,
Oct 1, 2014, 5:16:57 PM10/1/14
to mobile-c...@googlegroups.com
The database name is "workMax"

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/VwKv2PpF1Pw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/002181B4-B18E-4792-956A-EF2049211F88%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Jens Alfke

unread,
Oct 1, 2014, 5:27:35 PM10/1/14
to mobile-c...@googlegroups.com

On Oct 1, 2014, at 2:16 PM, Peter Jacobson <pjac...@surgeforward.com> wrote:

The database name is "workMax"

As I said in the last message, database names cannot contain capital letters. "M" is a capital letter.

—Jens

Peter Jacobson

unread,
Oct 1, 2014, 9:50:58 PM10/1/14
to mobile-c...@googlegroups.com
d’oH! I read the docs as “not BEGIN” with capital letter. Database is now showing as created. Progress…

Now I’m getting a 412, [Error] Failed to load resource: the server responded with a status of 412 (Precondition Failed) (workmax, line 0)



--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.

To unsubscribe from this group and all its topics, send an email tomobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Oct 1, 2014, 9:56:03 PM10/1/14
to mobile-c...@googlegroups.com
412 just means the db already exists, so you're good.

--Jens     [via iPhone]
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/97524115-038A-4D63-BA17-7E331DE5A32E%40surgeforward.com.

Peter Jacobson

unread,
Oct 1, 2014, 10:02:37 PM10/1/14
to mobile-c...@googlegroups.com
freakin awesome. Can’t believe I missed that one.



On Oct 1, 2014, at 8:55 PM, Jens Alfke <je...@couchbase.com> wrote:

412 just means the db already exists, so you're good.

--Jens     [via iPhone]

On Oct 1, 2014, at 6:50 PM, Peter Jacobson <pjac...@surgeforward.com> wrote:

d’oH! I read the docs as “not BEGIN” with capital letter. Database is now showing as created. Progress…

Now I’m getting a 412, [Error] Failed to load resource: the server responded with a status of 412 (Precondition Failed) (workmax, line 0)



On Oct 1, 2014, at 4:28 PM, Jens Alfke <je...@mooseyard.com> wrote:


On Oct 1, 2014, at 2:16 PM, Peter Jacobson <pjac...@surgeforward.com> wrote:

The database name is "workMax"

As I said in the last message, database names cannot contain capital letters. "M" is a capital letter.

—Jens
--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visithttps://groups.google.com/d/topic/mobile-couchbase/VwKv2PpF1Pw/unsubscribe.
To unsubscribe from this group and all its topics, send an email tomobile-couchba...@googlegroups.com.
To view this discussion on the web visithttps://groups.google.com/d/msgid/mobile-couchbase/3409052B-C9D6-41BC-83BB-55757D896344%40mooseyard.com.
For more options, visithttps://groups.google.com/d/optout.
--
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 tomobile-couchba...@googlegroups.com.
To view this discussion on the web visithttps://groups.google.com/d/msgid/mobile-couchbase/97524115-038A-4D63-BA17-7E331DE5A32E%40surgeforward.com.

For more options, visithttps://groups.google.com/d/optout.
--

You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visithttps://groups.google.com/d/topic/mobile-couchbase/VwKv2PpF1Pw/unsubscribe.
To unsubscribe from this group and all its topics, send an email tomobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Oct 2, 2014, 12:47:35 PM10/2/14
to mobile-c...@googlegroups.com

On Oct 1, 2014, at 7:02 PM, Peter Jacobson <pjac...@surgeforward.com> wrote:

freakin awesome. Can’t believe I missed that one.

:) It's a weird status code, but that's the CouchDB behavior so we use it for compatibility.
Let us know if the REST API docs could be clearer on that (I'm writing this on the train so I can't easily check them right now.)

—Jens

Peter Jacobson

unread,
Oct 2, 2014, 12:52:22 PM10/2/14
to mobile-c...@googlegroups.com
For me maybe the biggest undocumented thing to date is, “what is the host url for a local device when you are not using couchbase server at all?” I ended up doing a check and getting it then trimming the last “/“ to use it in the app. iOS and Android are completely different. 

Overall I didn’t find much to explicitly say, “if you aren’t using couchbase server or doing sync, here’s how it works.” Especially for phonegap. I found myself wishing there was a simple CRUD tut for that.

_pj




--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visithttps://groups.google.com/d/topic/mobile-couchbase/VwKv2PpF1Pw/unsubscribe.
To unsubscribe from this group and all its topics, send an email tomobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Oct 2, 2014, 2:18:03 PM10/2/14
to mobile-c...@googlegroups.com

On Oct 2, 2014, at 9:52 AM, Peter Jacobson <pjac...@surgeforward.com> wrote:

For me maybe the biggest undocumented thing to date is, “what is the host url for a local device when you are not using couchbase server at all?” I ended up doing a check and getting it then trimming the last “/“ to use it in the app. iOS and Android are completely different. 

Are you talking about the base URL to use with PhoneGap? That's the same whether or not you use sync. And I thought the app initialization code from the PhoneGap plugin passed it to you. (The PhoneGap based sample apps should show how to get it, in any case.)

—Jens

Peter Jacobson

unread,
Oct 2, 2014, 2:25:09 PM10/2/14
to mobile-c...@googlegroups.com
I got it from the app init yes. But this is exactly what confused me:

"Are you talking about the base URL to use with PhoneGap? That’s the same whether or not you use sync”

I would have thought there would be some canonical localhost-type URL to talk to a local vs a remote couchbase daemon. I didn’t realize there isn’t one and that you have to get it from the plugin, so I spent several hours assuming I had a bad URL (in part because of the 400 error message) and trying different URLs (e.g. couchdb uses http://0.0.0.0:5984). Some clearer indication of that in the docs would be a big help - I couldn’t find anything that specified this.

_peter

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visithttps://groups.google.com/d/topic/mobile-couchbase/VwKv2PpF1Pw/unsubscribe.
To unsubscribe from this group and all its topics, send an email tomobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Oct 2, 2014, 5:26:33 PM10/2/14
to mobile-c...@googlegroups.com
On Oct 2, 2014, at 11:25 AM, Peter Jacobson <pjac...@surgeforward.com> wrote:

"Are you talking about the base URL to use with PhoneGap? That’s the same whether or not you use sync”

I would have thought there would be some canonical localhost-type URL to talk to a local vs a remote couchbase daemon.

No, you never talk directly to a server. Only the replicator does that. (As you probably by now realize.)

I didn’t realize there isn’t one and that you have to get it from the plugin, so I spent several hours assuming I had a bad URL (in part because of the 400 error message) and trying different URLs (e.g. couchdb uses http://0.0.0.0:5984). Some clearer indication of that in the docs would be a big help - I couldn’t find anything that specified this.

I think this isn't documented because we assume devs will start from a PhoneGap example project and build the app from there, instead of trying to start from scratch with just the PhoneGap plugin. (But I don't work on our PhoneGap integration so I shouldn't speculate too much.)

FYI, the reason for the different URLs is that while iOS uses a URL-protocol plugin to catch the request before it hits the wire, you apparently can't do that on Android; so the Android version has to open a real live TCP listener socket. That socket will end up with an effectively-random port number, so the URL can't be hardcoded.

—Jens

Peter Jacobson

unread,
Oct 2, 2014, 6:06:06 PM10/2/14
to mobile-c...@googlegroups.com, mobile-c...@googlegroups.com
I would suggest it’s a bad assumption to make about starting from the example app. In my case, since all the sample apps are built assuming sync gateway it didn’t answer that question for me.

Also I’m not sure I expressed that very well, I didn’t mean “talking directly to the server”.

Thanks for all the info, esp the URL-generation info, that’s great to know.

_peter

On Oct 2, 2014, at 4:27 PM, Jens Alfke <je...@couchbase.com> wrote:


On Oct 2, 2014, at 11:25 AM, Peter Jacobson <pjac...@surgeforward.com> wrote:

"Are you talking about the base URL to use with PhoneGap? That’s the same whether or not you use sync”

I would have thought there would be some canonical localhost-type URL to talk to a local vs a remote couchbase daemon.

No, you never talk directly to a server. Only the replicator does that. (As you probably by now realize.)

I didn’t realize there isn’t one and that you have to get it from the plugin, so I spent several hours assuming I had a bad URL (in part because of the 400 error message) and trying different URLs (e.g. couchdb useshttp://0.0.0.0:5984). Some clearer indication of that in the docs would be a big help - I couldn’t find anything that specified this.

I think this isn't documented because we assume devs will start from a PhoneGap example project and build the app from there, instead of trying to start from scratch with just the PhoneGap plugin. (But I don't work on our PhoneGap integration so I shouldn't speculate too much.)

FYI, the reason for the different URLs is that while iOS uses a URL-protocol plugin to catch the request before it hits the wire, you apparently can't do that on Android; so the Android version has to open a real live TCP listener socket. That socket will end up with an effectively-random port number, so the URL can't be hardcoded.

—Jens
--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visithttps://groups.google.com/d/topic/mobile-couchbase/VwKv2PpF1Pw/unsubscribe.
To unsubscribe from this group and all its topics, send an email tomobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Oct 2, 2014, 6:46:35 PM10/2/14
to mobile-c...@googlegroups.com

On Oct 2, 2014, at 3:06 PM, Peter Jacobson <pjac...@surgeforward.com> wrote:

I would suggest it’s a bad assumption to make about starting from the example app. In my case, since all the sample apps are built assuming sync gateway it didn’t answer that question for me.

That's a fair point. Although really the only bit of the example apps that assumes you're using the gateway is the couple of lines that start the replication (the POSTs to /_replicate.) Take those out and the app is strictly local.

—Jens

Daniel Matejka

unread,
Dec 4, 2014, 8:53:12 AM12/4/14
to mobile-c...@googlegroups.com
Hi,
I have to agree with Peter. Step-by-step tutorial on CRUD app with explanation would save a lot of pain in the ..  would help a lot. I know the stuff seems to be basic and obvious for you, but not for those who see it for the first time.
Especially for phonegap, there is really lack of documentation to start with.

Best regards,

Daniel

Pete Jacobson

unread,
Dec 4, 2014, 11:23:31 AM12/4/14
to mobile-c...@googlegroups.com
After a lot of trial and error plus some input from J Chris, I finally got this stuff working and will try to write a tut myself BTW (in my (cough) spare time)

_peter

-- 

You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.

To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Dec 4, 2014, 11:28:36 AM12/4/14
to mobile-c...@googlegroups.com

On Dec 4, 2014, at 5:53 AM, Daniel Matejka <danielma...@gmail.com> wrote:

I have to agree with Peter. Step-by-step tutorial on CRUD app with explanation would save a lot of pain in the ..  would help a lot. I know the stuff seems to be basic and obvious for you, but not for those who see it for the first time.

We have a bunch of recorded webinars on Couchbase Lite, such as this one that I gave on getting started on iOS. Is that the sort of thing you're looking for? (The list of webinars doesn't let you filter by topic, so you'll have to page through it to find the mobile ones, sorry.)

—Jens

Pete Jacobson

unread,
Dec 4, 2014, 11:33:42 AM12/4/14
to mobile-c...@googlegroups.com
For me it wasn’t iOS, there are plenty of docs on that (well, relatively plenty). For Phonegap it’s difficult to find anything.

I personally don’t like learning from videos anyway, I prefer an article with code that walks me through at my own pace, without having to follow along as somebody talks through things.

_peter

On Dec 4, 2014, at 10:28 AM, Jens Alfke <je...@couchbase.com> wrote:


On Dec 4, 2014, at 5:53 AM, Daniel Matejka <danielma...@gmail.com> wrote:

I have to agree with Peter. Step-by-step tutorial on CRUD app with explanation would save a lot of pain in the .. would help a lot. I know the stuff seems to be basic and obvious for you, but not for those who see it for the first time.

We have a bunch of recorded webinarson Couchbase Lite, such as this onethat I gave on getting started on iOS. Is that the sort of thing you're looking for? (The list of webinars doesn't let you filter by topic, so you'll have to page through it to find the mobile ones, sorry.)

—Jens

-- 

You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.

To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Dec 4, 2014, 12:27:55 PM12/4/14
to mobile-c...@googlegroups.com

On Dec 4, 2014, at 8:33 AM, Pete Jacobson <pjac...@surgeforward.com> wrote:

For me it wasn’t iOS, there are plenty of docs on that (well, relatively plenty). For Phonegap it’s difficult to find anything.

Good point. I'm getting the feeling (based on list traffic here) that PhoneGap is more popular than we'd expected, and we may not be prioritizing it enough in our documentation & other developer support. Also, we have only one engineer who's an expert on it, and he's been very busy with some other tasks lately. I'll see if I can get things stirred up.

There are other sources of documentation, though. Once you get past the packaging issues — building the app and getting the root URL of the REST API — developing a CBL PhoneGap app is almost identical to developing what's called a "CouchApp" with CouchDB. You may find the online resources about CouchApps and CouchDB APIs useful. It can be a bit tricky to find, though, because the top search hits for [couchapp] are for the framework of the same name, which was the original way to build those apps but is now obsolete/unsupported. A better place to start would be the Kanso framework.

Hope that helps!

—Jens

Daniel Matejka

unread,
Dec 5, 2014, 3:57:05 PM12/5/14
to mobile-c...@googlegroups.com
let us know if you manage to write anything ... I would like to make similar statement, but as I am NooB in the mobile developement I doubt it would be useful... ;)

Daniel Matejka

unread,
Dec 5, 2014, 4:00:51 PM12/5/14
to mobile-c...@googlegroups.com
thank you for the hint.. I saw them all..:-) but do not want to go into native really... too expensive for small shop to do both platforms separetly..

Daniel Matejka

unread,
Dec 5, 2014, 4:09:11 PM12/5/14
to mobile-c...@googlegroups.com
I think couchbase lite would be much more popular if you would spend some more time on tutorials and docs for phonegap. Everybody wants to have mobile app ocasionally offline.. ?
Take a look on ionicframework (cordova + angularjs optimized for mobile) - they are getting some real movement and already have some "best of store" apps in both ios and android.
IMHO this is the train you should catch ;)

Jens Alfke

unread,
Dec 5, 2014, 4:55:58 PM12/5/14
to mobile-c...@googlegroups.com

On Dec 5, 2014, at 1:09 PM, Daniel Matejka <danielma...@gmail.com> wrote:

I think couchbase lite would be much more popular if you would spend some more time on tutorials and docs for phone gap. 

According to some statistics I just looked up, PhoneGap is used in about 6% of mobile apps, representing 1% of installs. So it wouldn't be that big a boost. But I agree that we should provide more resources for developing with it.

—Jens

Daniel Matejka

unread,
Dec 5, 2014, 5:34:22 PM12/5/14
to mobile-c...@googlegroups.com

the hybrid is only starting as the performance gap diminishes.. ionic is still in beta, foundation released their app framework just today.. mobiles are getting faster and javascript css3 and html5 are providing viable alternative to produce apps that cannot be distingushed from native.. it is just starting and will be more and more important.
especially data driven apps are best fit for web apps...morover angular is talking JSON natively... can you see the fit? I certainly do...

best regards

Daniel

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.

To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.

Pete Jacobson

unread,
Dec 5, 2014, 5:50:12 PM12/5/14
to mobile-c...@googlegroups.com
I’m going to say right now I’m not a huge fan of non-native apps except for very specific use cases (like the one I’m building this current app for). 

However, that stat is 6% of apps in the Google Play store. 6% of 1.420,134 (from your link) is still something like 85000 apps. And I think it’s not a stretch to assume that figure will also apply to iOS, which according to Statista has 1.2MM apps hence another 70k+. That seems significant to me, esp if couchbase can convert a decent number of them to paying customers.

Priorities are priorities of course - 94% is a much higher figure obviously…



On Dec 5, 2014, at 3:55 PM, Jens Alfke <je...@couchbase.com> wrote:


On Dec 5, 2014, at 1:09 PM, Daniel Matejka <danielma...@gmail.com> wrote:

I think couchbase lite would be much more popular if you would spend some more time on tutorials and docs for phone gap. 

According to some statisticsI just looked up, PhoneGap is used in about 6% of mobile apps, representing 1% of installs. So it wouldn't be that big a boost. But I agree that we should provide more resources for developing with it.

—Jens

-- 

You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.

To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.

Zack Gramana

unread,
Dec 5, 2014, 11:05:37 PM12/5/14
to <mobile-couchbase@googlegroups.com>
Regardless of market share, we need to improve our docs story for PhoneGap. We are actively working on it.

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/EDE8C7DD-CB24-4B40-A396-37B2B68A0F78%40surgeforward.com.

Daniel Matejka

unread,
Dec 6, 2014, 1:29:01 PM12/6/14
to mobile-c...@googlegroups.com
Great news.. looking forward to read anything
Reply all
Reply to author
Forward
0 new messages