Log Couchbase Query Results In Nativescript

Issue

I’m new to Nativescript and Couchbase, but when executing a query against my Couchbase database I simply want to log the results. Here is my example code:

let rows = this.database.executeQuery('profiles');

  for(let i = 0; i < rows.length; i++) {
     this.profiles.push(rows[i]);
  }

When trying to log “rows” using console.log I get the expected [Object object]. I thought I could use console.dir, but when doing that I get:

JS: === dump(): dumping members ===

JS: “rows: “

JS: === dump(): dumping function and properties names ===

JS: 0: r

JS: 1: o

JS: 2: w

JS: 3: s

JS: 4: :

JS: 5:

JS: 6:

JS: === dump(): finished ===

Is there a way to log the actual results from executeQuery?

Solution

If you are happy to log out the results from the rows array after they have been collected, you could just use JSON.stringify(), and enumerate over the array. Which might look something like this:

rows.forEach(row => {
    console.log(JSON.stringify(row))
})

Answered By – George Edwards

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.