java - Fastest Way to Access MongoDB through Jetty -


i have web app i'm running through angularjs, server side run through jetty , database mongodb. right now, way have webapp accessing database through websockets, feel not best/fastest way this, because i've found takes large amount of time process data. i'm wondering best way access data through javascript, jetty, , mongodb. thanks! browser code:

getdatawebsocket.onmessage= function(event){                 var data = "[{" +                 event.data.substring(0, event.data.length-1) +                 "]";                 $scope.data = json.parse(data);                 console.log(json.parse(data));                 console.log($scope.data);             }; 

jetty code

try {                 mongoclient mongoclient = new mongoclient("localhost", 27017);                 db db = mongoclient.getdb("mydb");                 dbcollection collection = db.getcollection("mycollection");                 dbcursor cursor = collection.find();                 string data = "";                 while (cursor.hasnext()){                     dbobject next = cursor.next();                     data += (json.serialize(next)).tostring() + ",";                 }                 data = data.substring(0, data.length());                 sendmessage(data, session);             }catch(exception e){                 sendmessage(e.getclass().getname() + ": " + e.getmessage(), session);                 system.err.println(e.getclass().getname() + ": " + e.getmessage());             } 


Comments