triniwiz/nativescript-couchbase-plugin

how to get count of items from document

Closed this issue · 4 comments

Do we have a method that returns count/length of items in any document of database ?

let db = new Couchbase("database");
const data = [ { ...}, {...}, {...}] // lets say 10 records

let documentId = db.createDocument(
{ "data": data },
);

how to get count 10 from documentId ? not seeing any direct method for it. pls suggest.

You will need to use the if returned after creating the new document then call getDocument

You will need to use the if returned after creating the new document then call getDocument

Not sure if I understand correctly. Is it possible for you to provide code snippet related to same.

let db = new Couchbase("database");
const data = [ { ...}, {...}, {...}] // lets say 10 records

let documentId = db.createDocument(
{ "data": data },
);
const document = db.getDocument(documentId);
const count = document.data.length
let db = new Couchbase("database");
const data = [ { ...}, {...}, {...}] // lets say 10 records

let documentId = db.createDocument(
{ "data": data },
);
const document = db.getDocument(documentId);
const count = document.data.length

this worked. Thank you.

I was trying other way, but not suggested/preferred, I guess
const databaseQuery = await db.query({select: [], });
console.log("content length", databaseQuery[0].data.length);