iOS Swift: Questions

51 views
Skip to first unread message

parvez....@decurtis.com

unread,
Oct 30, 2017, 11:02:34 AM10/30/17
to Couchbase Mobile
For a Couchbase lite iOS application, 
1.Is it possible to create a CBLView with multiple emit statements like
emit([key1,key2,key3],doc)
emit([key4,key5,key6],doc)

2. Do we need to add some kind of hash value when we specify an endKey for a CBLLiveQuery?


Thanks

Traun Leyden

unread,
Oct 30, 2017, 1:18:11 PM10/30/17
to mobile-c...@googlegroups.com
That should work as far as I know, but if you emit the entire doc (multiple times) it's really going to bloat your index.  More discussion here and here.  These discussions are about CouchDB, but should apply to CBLite 1.4 as well.

Please give it a shot and report back if you run into issues.


2. Do we need to add some kind of hash value when we specify an endKey for a CBLLiveQuery?


Can you give details on what problem you're trying to solve here?


 

Thanks

--
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-couchbase+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/81b3283c-b8c3-4e13-8c52-6bdff2eb5614%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

parvez....@decurtis.com

unread,
Nov 1, 2017, 9:46:46 AM11/1/17
to Couchbase Mobile
Consider emit as below:
emit([key1,key2,key3,key4],doc)
emit([key3,key2,key1,key4],doc)

In android we require to specify a hash map at the end in endKey so I want to know if we need to specify any such information in iOS swift as well?

Also can we specify same key values in both startKey & endKey?

Traun Leyden

unread,
Nov 1, 2017, 1:57:46 PM11/1/17
to mobile-c...@googlegroups.com
It sounds like you are asking about querying.  Check out:


in particular the section:

Unfortunately this has obvious problems. The correct stop value to use turns out to be an empty object/dictionary, {}, making the end key ["red", {}]. This works because the sort order in views puts dictionaries last.


--
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-couchbase+unsubscribe@googlegroups.com.

Jens Alfke

unread,
Nov 1, 2017, 4:38:12 PM11/1/17
to Couchbase Mobile


On Oct 30, 2017, at 8:02 AM, parvez....@decurtis.com wrote:

1.Is it possible to create a CBLView with multiple emit statements like
emit([key1,key2,key3],doc)
emit([key4,key5,key6],doc)

Sure, it’s a common technique.

(As for emitting ‘doc’ as the value — it’s not advisable, but common enough that we added a workaround for it. The contents of the doc aren’t actually emitted into the view, but the QueryRow object’s .value property will load and return the document anyway.
(What is advisable is to figure out what info about the document you need to know when querying, and then emit that as the value.)

—Jens

Parvez Qureshi

unread,
Nov 8, 2017, 12:49:35 PM11/8/17
to mobile-c...@googlegroups.com
For an emit with key as an array of say 4 fields, if we specify group level as 3 then will the keys parameter of reduce function will also be an array with element count as 3? I mean to say does group level decides the number of fields in each item of keys parameter of reduce function?


From: mobile-c...@googlegroups.com <mobile-c...@googlegroups.com> on behalf of Jens Alfke <je...@couchbase.com>
Sent: Thursday, November 2, 2017 2:08:08 AM
To: Couchbase Mobile
Subject: Re: iOS Swift: Questions
 
--
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/LRZP2eWPvXA/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/018B53C5-2DF1-48B9-A0DF-1AE890D4C138%40couchbase.com.

Parvez Qureshi

unread,
Nov 8, 2017, 2:28:40 PM11/8/17
to mobile-c...@googlegroups.com
Another question

For an emit with key array as [String, NSNumber,String,Double] where 2nd parameter is a Boolean and fourth one is a time interval field, if I specify an array of [String, Number] as startkey and group level as 3 then reduce function does not execute but if I omit startkey then I am able to get output from reduce function. There is also an endkey corresponding to startkey as [ String, NSNumber,[:]]

The values specified in start/ end keys exists in emitted keys. What's wrong with start/ endkey usage?




From: mobile-c...@googlegroups.com <mobile-c...@googlegroups.com> on behalf of Jens Alfke <je...@couchbase.com>
Sent: Thursday, November 2, 2017 2:08:08 AM
To: Couchbase Mobile
Subject: Re: iOS Swift: Questions
 
--

Jens Alfke

unread,
Nov 8, 2017, 5:27:35 PM11/8/17
to mobile-c...@googlegroups.com


> On Nov 8, 2017, at 9:49 AM, Parvez Qureshi <parvez....@decurtis.com> wrote:
>
> For an emit with key as an array of say 4 fields, if we specify group level as 3 then will the keys parameter of reduce function will also be an array with element count as 3? I mean to say does group level decides the number of fields in each item of keys parameter of reduce function?

Yes, I believe so. Give it a try and make sure; it’s been a while since I worked with map/reduce.

—Jens

parvez....@decurtis.com

unread,
Nov 10, 2017, 8:19:58 AM11/10/17
to Couchbase Mobile
Even after specifying groupLevel as 3, I always receive four elements in each row of keys array of reduce block. Also If I specify startKey / endKey then query do not return any result (reduce block is not executed) but if I omit startKey / endKey then I am able to get results in reduce function. I have made sure that couchbase is having records corresponding to values specified in startKey/EndKey but still then it do not works. I am using Couchbase lite 1.3.1 (build 6) with iOS Swift 3.0.

How this issue cab be troubleshooted?

Jens Alfke

unread,
Nov 14, 2017, 12:41:12 PM11/14/17
to mobile-c...@googlegroups.com


> On Nov 10, 2017, at 5:19 AM, parvez....@decurtis.com wrote:
>
> Even after specifying groupLevel as 3, I always receive four elements in each row of keys array of reduce block. Also If I specify startKey / endKey then query do not return any result (reduce block is not executed) but if I omit startKey / endKey then I am able to get results in reduce function. I have made sure that couchbase is having records corresponding to values specified in startKey/EndKey but still then it do not works. I am using Couchbase lite 1.3.1 (build 6) with iOS Swift 3.0.
>
> How this issue cab be troubleshooted?

Thinking further … the group-level shouldn’t affect the calls to the reduce function, so that part is behaving correctly. (In CouchDB, reducing happens when the index is built, not at query time at all; CBL can’t perform that optimization, but it still follows the same semantics of the reduce function.)

The part about startKey/endKey might be a bug, though. You can file an issue, but please provide detailed information such as the contents of the documents, and the exact parameters of the query.

Are you actually getting incorrect results from the query? If so, what did you expect and what did you get?

—Jens

parvez....@decurtis.com

unread,
Dec 7, 2017, 8:03:30 AM12/7/17
to Couchbase Mobile
I have filed an issue over GitHub.

Parvez Qureshi

unread,
Dec 7, 2017, 12:48:25 PM12/7/17
to mobile-c...@googlegroups.com
Currently I am using pods for Couchbase lite iOS SDK framework. If one want to include couchbase lite iOS SDK source code for version 1.4.1 then how we can include it in a swift iOS project? Please suggest.

From: mobile-c...@googlegroups.com <mobile-c...@googlegroups.com> on behalf of parvez....@decurtis.com <parvez....@decurtis.com>
Sent: Thursday, December 7, 2017 6:33:30 PM

To: Couchbase Mobile
Subject: Re: iOS Swift: Questions
--
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/LRZP2eWPvXA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.

Jens Alfke

unread,
Dec 12, 2017, 1:48:11 PM12/12/17
to mobile-c...@googlegroups.com


On Dec 7, 2017, at 9:48 AM, Parvez Qureshi <parvez....@decurtis.com> wrote:

Currently I am using pods for Couchbase lite iOS SDK framework. If one want to include couchbase lite iOS SDK source code for version 1.4.1 then how we can include it in a swift iOS project? Please suggest.

Add the Couchbase Lite Xcode project to your project as a subproject. Then add the CBL Swift framework as a dependency of your app target, and as a linked framework.

—Jens

Jens Alfke — Mobile Architect — Couchbase, Inc.

Reply all
Reply to author
Forward
0 new messages