Zach Smith
Zach Smith

Reputation: 8971

CouchDB seems to implement MapReduce differently to couchbase-lite

On couchDB I have the following view:

function(doc) {
  if(doc._id === 'countryMobileNumberCodes') {
    Object.keys(doc.dictionary).forEach(function(k, i) {
      emit(k, doc.dictionary[k]);
    });
  }
}

This emits the following result:

{"total_rows":2,"offset":0,"rows":[
{"id":"countryMobileNumberCodes","key":"1","value":"+265"},
{"id":"countryMobileNumberCodes","key":"2","value":"+27"}
]}

This same view on Android (using couchbase-lite-android 1.2.1) does not emit any rows. However, if I were to change the view to this:

function(doc) {
  if(doc._id === 'countryMobileNumberCodes') {
    emit(doc._id, doc.dictionary);
  }
}

Then I do get results from couchbase-lite (so the docs definitely exist on the mobile device).

Does CouchDB implement MapReduce differently to couchbase-lite?

I have seen reference to the fact that couchbase-lite and CouchDB are 100% compatible, but that does not seem to be the case (Couchbase-lite and CouchDB).

Upvotes: 1

Views: 121

Answers (1)

Jens Alfke
Jens Alfke

Reputation: 1981

Presumably you are using Couchbase Lite's REST API, probably within PhoneGap or Cordova. It looks as though the JavaScript interpreter in that container doesn't support Object.keys or foreach(). You'll probably need to rewrite your map and reduce functions using only older features of JavaScript.

(My JS is very rusty so I can't tell you what version of the language added those APIs. It's also possible they're not built-in but are part of a library that CouchDB includes in its JS context as a convenience.)

Upvotes: 0

Related Questions