triniwiz / nativescript-couchbase-plugin

Apache License 2.0
52 stars 19 forks source link

how to get count of items from document #48

Closed PiyushHM closed 4 years ago

PiyushHM commented 4 years ago

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.

triniwiz commented 4 years ago

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

PiyushHM commented 4 years ago

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.

triniwiz commented 4 years ago
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
PiyushHM commented 4 years ago
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);