cordovaionic-frameworkcouchbase-litecouchbase-viewcordova-android

Couchbase Lite views doesnt work after any document update


  1. We have couchbase lite application. We use views to display data on the app. There is one design doc and that contains four views.
  2. The design doc and views are created after database is ready. Views are created only once.
  3. When we change any document or create a new document that would have gone to a view, the view stops returning documents on next query. It gives error

    {"error":"bad_request","status":400,"reason":"Router unable to route request to do_GET_DesignDocumentcom.couchbase.lite.CouchbaseLiteException: Cannot index view cceDesignDoc/draftTransactionView: no map block registered, Status: 400 (HTTP 400 bad_request)"}

  4. The view works when we use Couchbase Lite 1.4.0. It doesn't work when we upgrade to 1.4.4.

We are using views through REST API similar to the following:

http://a638931f-0e15-7389-1ae0-q1f7491ac748:72e61883-ca1d-8391-ad1e-474299b8c9a3@localhost:5984/local2368288277/_design/abcDesignDoc/_view/peterAbcTransactionView?

Please see relevant code below:

// This method is called when app starts up. It is called only once.    
public createView(){
    this.platform.ready().then(() => {
        (new Couchbase()).openDatabase(AppUrl.LOCAL_DB_NAME).then(database => {
            this.database = database;
            let views = {
                myAbcTransactionView: {
                    map: function (doc) {
                        if (doc.type == "myAbcTransaction") {
                            emit(doc._id, doc)
                        }
                    }.toString()
                },
                johnAbcTransactionView: {
                    map: function (doc) {
                        if (doc.type == "johnAbcTransaction") {
                            emit(doc._id, doc)
                        }
                    }.toString()
                },
                peterAbcTransactionView: {
                    map: function (doc) {
                        if (doc.type == "peterAbcTransaction") {
                            emit(doc._id, doc)
                        }
                    }.toString()
                },
                jennaAbcTransactionView: {
                    map: function (doc) {
                        if (doc.type == "jennaAbcTransaction") {
                            emit(doc._id, doc)
                        }
                    }.toString()
                }
            };

            this.database.createDesignDocument("_design/abcDesignDoc", views);

            this.database.listen(change => {
                this.listener.emit(change.detail);
            });
        }
    }

//This method is called to show records in the view on the screen   
public showRecords() {
    this.couchbase.getDatabase().queryView("_design/abcDesignDoc", "peterAbcTransactionView", {}).then((result: any) => {
      this.transactions = [];

      for (var i = 0; i < result.rows.length; i++) {
        this.zone.run(() => {

          this.transactions.push(result.rows[i].value);
          this.transactions.sort(function (b, a
          ) {
            return a.theDate - b.theDate;
          });
        });
      }
    }, error => {
    });
  }

Version Information: Ionic:

ionic (Ionic CLI) : 4.7.1 (AppData\Roaming\npm\node_modules\ionic) Ionic Framework : ionic-angular 3.3.0 @ionic/app-scripts : 1.3.7

Cordova:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : android 7.1.4 Cordova Plugins : no whitelisted plugins (14 plugins total)

System:

NodeJS : v6.14.4 (C:\Program Files\nodejs\node.exe) npm : 3.10.10 OS : Windows 10

Couchbase Lite : 1.4.4

Couchbase-Lite-PhoneGap-Plugin: (https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin)


Solution

  • We have found that couchbase-lite 1.4.4 has the issue for above error. When we install couchbase-lite 1.4.0 and after that everything will be working fine till now.