+1 for adding doc pointer de-referencing before calling the map function.

On Oct 24, 2014, at 3:44 PM, Traun Leyden 
<[email protected]<mailto:[email protected]>> wrote:


I'm working on some changes for the 
officeradar<https://github.com/tleyden/office-radar> demo app and trying to 
show a list of profiles which I want to have reverse sorted by how recent 
they've had a geofence event for that profile.  Eg:

[Traun entered SF 5 hours ago]
[Zack entered SF 8 hours ago]
[Hideki entered MV 2 days ago]

The document model is as follows:

Profile doc

{
   "_id":"tleyden",
   "lastGeofenceEvent":"doc-234324232"
}

GeofenceEvent doc

{
   "id":"doc-234324232",
   "createdAt":"2014-10-24",
   "beaconLocation":"sf"
}


As I was writing the map function to generate the UI mentioned above, I wanted 
to emit the createdAt field, but realized that would require a doc lookup.  Eg:

Mapper map = new Mapper() {
                @Override
                public void map(Map<String, Object> document, Emitter emitter) {
                    if (document.get("type").equals("profile")) {

                        // I have a profile doc, but I only have the id of the
                        // latest geofence event associated with this profile,
                        // and I'd need to do a db lookup to get it, which
                        // would violate the rules of a map function .. so I'm 
stuck

                    }
                }
            };

Proposed solution

I figured I could add a new field to the profile doc to hold the date of the 
latest geofence event associated with this profile (denormalize + duplicate):

Profile doc (updated):

{
   "_id":"tleyden",
   "lastGeofenceEvent":"doc-234324232",
   "lastGeofenceEventCreatedAt":"2014-10-24"
}

The map function would become:

                  if (document.get("type").equals("profile")) {

                        emit(document.get("lastGeofenceEventCreatedAt"), ...);

                   }

and the problem would be solved.

But, I'm wondering is this the best practice or is there a better way?  @Jens I 
remember in your advanced couchbase lite talk you mentioned "poor man's joins", 
but I didn't catch the details.  Would that apply here?


--
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 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/CACSSHCEyDD2EdKYVERZAcdG5N5VjonGaeHSW1mntX8DXeWYLTw%40mail.gmail.com<https://groups.google.com/d/msgid/mobile-couchbase/CACSSHCEyDD2EdKYVERZAcdG5N5VjonGaeHSW1mntX8DXeWYLTw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://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 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/AB6D9763-281E-4C78-BBDC-97B5EDF4DE47%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to