Couchbase plugin, error executing queries with existent views


I am using {NS} with Angular 5
I have an Angular service called dbService which create the couchbase instance in the constructor along with some views and also have some CRUD operations methods.

export class DbService {

db: Couchbase

constructor(private ) {
// create or open a database
this.db = new Couchbase(“testdb”);

    // create views, just for testing get every document
    this.db.createView('User', '1', (doc, emitter) => {
            emitter.emit(doc._id, doc);


private unwrap(doc, docId?) {
let instance = doc.instance; = docId ? docId : doc._id;
return instance;

private wrap(instance) {
    return {
        type: instance.$class,
        instance: instance

search(entity: string) {

    return Observable.create((observer: Observer<any>) => {
        // return results{
            data: this.db.executeQuery(entity)

get(entity: string, id: string) {
    return Observable.create((observer: Observer<any>) => {
        // get doc
        let doc = this.db.getDocument(id);
        // return instance, id));

insert(instance: any) {
    return Observable.create((observer: Observer<any>) => {
        // create doc
        let docId = this.db.createDocument(this.wrap(instance));
        let doc = this.db.getDocument(docId);
        // return instance, docId));

update(instance: any) {
    return Observable.create((observer: Observer<any>) => {
        // update doc
        this.db.updateDocument(, this.wrap(instance));
        let doc = this.db.getDocument(;
        // return instance,;

delete(instance: any) {
    return Observable.create((observer: Observer<any>) => {
        // return result of deletion;


If i try to use the dbService.insert() method it works as expected and inserts the document into the database:


But later when i try to do:‘User’).subscribe(results => {
// TODO: do something with results

I am getting this error:

CONSOLE ERROR [native code]: ERROR TypeError: null is not an object (evaluating ‘resultSet.nextRow’)
CONSOLE ERROR [native code]: ERROR CONTEXT [object Object]

That running the app in ios.
I don’t where else to look because i am limited to the methods the plugin exposes from the couchbase api.

Thanks in advance.


A few questions:

  • How do you know the insert truly worked? Did you try a get operation after based on the document key and it returned data?
  • What results do you get on Android? Just trying to narrow down if this is potentially an Android and iOS problem or just iOS.



The insert method returns the document just created with the id assigned by the database and i logged it in the console to make sure is being inserted, i haven’t tried in android i will now and let you know.


When trying to test it in android, i am using an android simulator and this is the error is giving me.

MANAGER ERROR: Cannot read property ‘AndroidContext’ of undefined

And from that point as database is null in the Couchbase instance all the other methods are failing.


Now this is the error is giving me in Android when trying to do the executeQuery

ERROR Error: com.couchbase.lite.CouchbaseLiteException: getViewID() < 0, Status: 404 (HTTP 404 not_found)
JS: com.couchbase.lite.View.updateIndexes(
JS: com.couchbase.lite.View.updateIndex(
JS: com.couchbase.lite.Database.queryViewNamed(
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(
JS: com.tns.Runtime.callJSMethodImpl(
JS: com.tns.Runtime.callJSMethod(
JS: com.tns.Runtime.callJSMethod(
JS: com.tns.Runtime.callJSMethod(
JS: android.view.View.performClick(
JS: android.view.View$
JS: android.os.Handler.handleCallback(
JS: android.os.Handler.dispatchMessage(
JS: android.os.Looper.loop(
JS: java.lang.reflect.Method.invoke(Native Method)
JS: ERROR CONTEXT [object Object]


Hey @rolandobermudez,

I spun up a new project on my end and checked to make sure it is using Angular 5.X and it is. I didn’t run into any issues, although I didn’t use your code.

I created a database.service.ts file within the project that contains the following:

import { Injectable } from "@angular/core";
import { Couchbase } from "nativescript-couchbase";

export class DatabaseService {

    private db: any;

    public constructor() {
        this.db = new Couchbase("test-database");
        this.db.createView("people", "1", (document, emitter) => {
            emitter.emit(document._id, document);

    public getDatabase() {
        return this.db;


Then I added the following code to the project’s app.module.ts file:

    bootstrap: [
    imports: [
    declarations: [
    providers: [
    schemas: [

More specifically note the providers array which now contains the previously created DatabaseService class.

Finally, I have the following code in the app.component.ts file:

import { Component, OnInit } from "@angular/core";
import { DatabaseService } from "./database.service";

    selector: "ns-app",
    templateUrl: "app.component.html",
export class AppComponent implements OnInit {

    private database: any;

    public constructor(private data: DatabaseService) {
        this.database = data.getDatabase();

    public ngOnInit() {
        this.database.createDocument({ "firstname": "Nic", "lastname": "Raboy" });
        let rows = this.database.executeQuery("people");
        for(let i = 0; i < rows.length; i++) {


Now that code is not complex so it doesn’t do a whole lot and doesn’t make use of any XML bindings, but all I was trying to do was make sure that data was added and that queries worked without issue.

When doing tns run ios, I looked at my console and it did what I expected.

What you might want to do is the following:

  1. Update your NativeScript CLI
  2. Update Xcode and any installed simulators
  3. Wipe out the projects node_modules, hooks, and platforms directories and do a tns install to get the latest and greatest without any chance of caching issues.

If my example works, but yours continues to fail, you may want to investigate how you’re working with observables. I’m sure @jen.looper or @JoshSommer could help you with that.



Thank you @nraboy for your help, while i was looking on how to fix this, i find out this other plugin called nativescript-couchbaselite which worked for me so decided to use it and now i have it working. One thing to notice is that using the previous plugin the Cocoa Pods for the couchbase lite was never installed in ios, at least i didn’t see logs of it in my terminal.


Awesome, glad you got something working :slight_smile: