so case: have program takes 2 large csv-files, finds diffs , sends array list method supposed update mongodb lines array. problem updates taking forever. test case 5000 updates takes 36 minutes. normal?
the update(list<string> changes)
-method this:
mongoclient = new mongoclient(ip); db = mongoclient.getdb("foo"); collection = db.getcollection("bar"); //for each line of change (string s : changes) { //splits csv-lines on ; string[] fields = s.split(";"); //identifies wich document in database updated long id = long.parselong(fields[0]); basicdbobject sq = new basicdbobject().append("organizationnumber",id); //creates new unit-object, converted json , inserted database. unit u = new unit(fields); gson gson = new gson(); string jsonobj = gson.tojson(u); dbobject objecttoupdate = collection.findone(sq); dbobject newobject = (dbobject) json.parse(jsonobj); if(objecttoupdate != null){ objecttoupdate.putall(newobject); collection.save(objecttoupdate); }
that's because taking steps update. don't need parse jsons manually , don't have query-then-update when can update "where" clause in single step.
something this:
basicdbobject query= new basicdbobject().append("organizationnumber",id); unit unit = new unit(fields); basicdbobject unitdb= new basicdbobject().append("somefield",unit.getsomefield()).append("otherfield",unit.getotherfield()); collection.update(query,unitdb);
where query
specifies "where" clause , unitdb
specifies fields need updated.
Comments
Post a Comment