legacy
legacy

Reputation: 241

Poorly Performing Query

I have a server I am using to store log files using mongodb. the problem is while browsing by revision I have a notable delay and a performace spike on the server. is there a better way to do the folowing:

function getrevisionslist(project,callback){
MongoClient.connect("mongodb://localhost:27017/devbed", {native_parser:true}, function(err, db) {
tmp=[]
      if(err) { console.dir(err); }
      db.collection(project).find({}).toArray(function(err, items) {
        fillrevarr(tmp,items,0,project,callback);
      db.close();
      });

  });
}

function fillrevarr(tmp,items,i,project,callback){
    console.log(items)
    num=JSON.stringify(items[i].revision).replace(/["']{1}/gi,"");
    tmp.push("<a href=\"/"+project+"/"+num+"/Log\">"+num+"</a>")
    if(i==items.length-1){callback(tmp)}
    else{fillrevarr(tmp,items,(i+1),project,callback)}
}

Which gives me an array of all revisions.

Upvotes: 0

Views: 69

Answers (1)

TheHippo
TheHippo

Reputation: 63179

Do not transform the resultset into an array. Use the cursor instead:

var cursor = db.collection(project).find({});
cursor.each(function(err, item) {
    // ...
});

Upvotes: 2

Related Questions