How to Update data in MongoDb with Java? -
hello every 1 working working on mongodb java. done connection insert , retrieve value mongodb when try update data code not working .
my code :
public static result updateprofile() throws unknownhostexception { final dynamicform profileform=form().bindfromrequest(); final string username1 = profileform.get("username"); final string password1 = profileform.get("password"); final string email1 = profileform.get("email"); final string userid = session("userid"); mongoclient mongo=new mongoclient("localhost",27017); db db = mongo.getdb("webportal"); dbcollection coll=db.getcollection("userdb"); basicdbobject doc2=new basicdbobject("_id", userid); basicdbobject doc1=new basicdbobject(); doc1.append("username", username1); doc1.append("username", username1); doc1.append("password", password1); doc1.append("email",email1 ); basicdbobject doc3=new basicdbobject("$set",doc1); coll.update(doc2, doc3); return ok(userid+username1); }
i read this block updating data in mongo
could please try this.
objectid id= new objectid("4f693d40e4b04cde19f17205"); basicdbobject searchquery = new basicdbobject(); searchquery .put("_id", id); basicdbobject updatedocument = new basicdbobject(); updatedocument .append("$set", new basicdbobject("username", username1)); coll.update(searchquery , updatedocument);
Comments
Post a Comment