Return after successful emit

18 views
Skip to first unread message

Ami Kapadia

unread,
Dec 4, 2014, 9:30:50 AM12/4/14
to mobile-c...@googlegroups.com
HI!

I am using CBL views in native iOS and Android for my PhoneGap app. 
Is there any way to return after successfully emit one record and jump to next record in view in CouchBaseLite?
For example, here is my view :





[[[[CBLManager sharedInstance] databaseNamed: self.dbName error: &error] viewNamed: [self.dbName stringByAppendingString:@"/typewise_data_of_user"]] setMapBlock: MAPBLOCK({
 
NSString *type = [doc objectForKey:@"type"];
if (type)
{
 
if([type isEqualToString:@"board"])
 emit
(type, NULL);
else
 
{
 BOOL is_active
= (BOOL)[doc objectForKey: @"is_active"];
 
if(is_active)
 
{
 
NSString *sales_rep = [doc objectForKey:@"sales_rep"];
 
if(sales_rep)
 
{
 emit
(@[type, sales_rep], NULL);
 
}
 
NSArray* owners = (NSArray*)[doc objectForKey:@"owners"];
 
if(owners)
 
{
 
for (NSDictionary* owner1 in owners)
 
{
 
NSString *o_id = [owner1 objectForKey:@"id"];
 
if(owner1 != NULL)
 
{
 emit
(@[type, o_id], NULL);
 
}
 
}
 
}
 
}
 
}
}
}) reduceBlock:NULL version: @"1.5"];




I want to check sales_rep and owners both in one view. So, here I need to directly move to next record after 1st emit. That means, when we found a record with proper sales_rep, then I don't want to check for owners. I want to directly check next record. 

Is there any functionality that allow me to return after successful emit?

Thanks!
Ami

Jens Alfke

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

On Dec 4, 2014, at 6:30 AM, Ami Kapadia <ami....@gmail.com> wrote:

Is there any way to return after successfully emit one record and jump to next record in view in CouchBaseLite?

Just use the "return" statement.

There's no such thing as "jumping" to another document. The map function is called separately for each document in the database (and it might be called in parallel on multiple documents at once on different threads; that's an implementation detail.)

The map function's job is simply to specify what data of a document should be indexed into the view. It only looks at one document at a time. Does that help clarify things?

—Jens

Ami Kapadia

unread,
Dec 4, 2014, 5:31:29 PM12/4/14
to mobile-c...@googlegroups.com
Thanks! It worked!

--
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/C8333D4A-4417-45AD-850F-02EE14EB802C%40couchbase.com.

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

Reply all
Reply to author
Forward
0 new messages