使用Java操作MongoDB - Update

Update

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Mongo mg = new Mongo("localhost", 27017);
// get db
db = mg.getDB("CRUD");
// get collection
dc = db.getCollection("test");

//Update
BasicDBObject query = new BasicDBObject();
query.put("name", "hulu22");
query.put("title", "PO");
BasicDBObject newDoc = new BasicDBObject();
newDoc.put("$set", new BasicDBObject("title", "PM").append("name", "hulu22"));// $unset: Removes the specified field from a document.

dc.update(query, newDoc);

dc.update(query, newDoc, false, false);

dc.updateMulti(query, newDoc);

唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!