2014년 12월 30일 화요일

Update using ObjectId as String in Java Interface (Swing)

Hi, I 'm trying to update a field knowing _id created by default MongoDB . What I do is that I insert a JTextField as a string, and then attempt to use it to update but I do not update anything. I understand it is because one is an object and the other is a String, so do not know if there is any option to turn it back into a objectid .

VisitasUpdate.update (new BasicDBObject ("_ id" , " 549d424be4b0a16103ec046f " ) ,
new BasicDBObject ( " $ set " new BasicDBObject ( "Time Check ", " 19:46:59 "))) ;



Have you tried the ObjectId constructor that takes a String parameter?




I'm using this code and works ok:

 ObjectId Id = new ObjectId("549d424be4b0a16103ec046f");
                  VisitasUpdate.update(new BasicDBObject("_id", Id),
                  new BasicDBObject("$set", new BasicDBObject("Hora Consulta", "21:46:59")));


댓글 없음:

댓글 쓰기