Hi
I’m using couchbase-nativescript plugin (with couchbase server 5.1.1 and Sync Gateway 2.0)
Following the readme, I did the following code to create and query a MapReduce view, where viewName
is the name of the view that’s going to be created, options
has the the executeQuery
options and fn
is a conditional function to filter some results.
public query(viewName, options, fn){
this.getDatabase().createView(viewName, "1", function(document, emitter) {
if(document.type == viewName){
emitter.emit(document._id, document);
}
});
let list = this.getDatabase().executeQuery(viewName, options);
let queryList = [];
if(fn){
for(var i = 0; i < list.length; i++){
if(fn(list[i])){
queryList.push(list[i]);
}
}
return queryList;
}else{
return list;
}
}
I have documents of the following type in my couchbase server
{
"data": {
"abo_aer": true,
"abo_flu": false,
"abo_ter": true,
"cer_com": "3",
"cod_com": "GTUI-VG-01",
"com_des": false,
"id_sec": null,
"id_sub_are": "c28f226f-8a4d-4a84-b235-2e45d6398df5",
"met_est": "",
"niv_end": "3",
"nom_com": "asdfg",
"nom_equ": [
"hjklf",
"dfgh",
"cvbn"
],
"ubi_com": {
"coordinates": [
2.73593333333333,
-64.1070833333333
],
"type": "Point"
}
},
"type": "communities"
}
Then I call the following function:
let communityList = this.couchbaseService.query("communities", {}, null);
And it does work, but takes too long to return the data (around 12 seconds only in the executeQuery
function for just 350 records). Is there a way to improve that time? I don’t think 350 records should take that long. Note that creating the view may take around 2 to 50 ms and I could move it to another function, but the real problem is during the executeQuery
function.
Thank you.