大家好,我是mongodb的新手。当我更新表时,我必须在result
中获得返回值。但它返回undefined
,但在find
和insert
的情况下,表中的值可以正常工作。
bands.update({name:'Hollywood Rose'}, {$set:{year:2000}}, function(err, result) {
console.log("result----"+result) // it returns undefined
if (!err)
return context.sendJson(result, 404);
})
;
答案 0 :(得分:1)
这个代码在我的情况下工作,而我更新mongodb表中的值我在java的playframe工作中做了这个代码。希望它对你的情况也有所帮助。
MongoClient mongo=new MongoClient("localhost",27017);
/*mongo.setWriteConcern(WriteConcern.JOURNALED);*/
DB db = mongo.getDB("webportal");
DBCollection coll=db.getCollection("userdb");
//ObjectId id= new ObjectId(userid);
BasicDBObject doc2 = new BasicDBObject();
doc2.put("_id",userid);
BasicDBObject updateDocument = new BasicDBObject();
updateDocument .append("$set", new BasicDBObject("username", username1).append("password", password1).append("email", email1));
coll.update(doc2, updateDocument);