使用Java操作MongoDB - Delete

Delete

1
2
3
4
5
6
7
8
9
10
Mongo mg = new Mongo("localhost", 27017);
// get db
db = mg.getDB("CRUD");
// get collection
dc = db.getCollection("test");

//Delete
DBObject doc = dc.findOne();
WriteResult result = dc.remove(doc);
System.out.println("Number of documents are deleted : " + result.getN());

1
2
3
// delete
WriteResult wr = dc.remove(new BasicDBObject("name", "tom"));
System.out.println(wr.getN());
唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!