用java 删除mongodb的数据

import java.net.UnknownHostException;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.Mongo;


public class DeleteData {

/**
* @param args
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException {
Mongo mongo=new Mongo("127.0.0.1",27017);//链接mongoDB
DB db=mongo.getDB("my");//获取my数据库
DBCollection collection=db.getCollection("t");//获取t集合
DBObject object=new BasicDBObject();
object.put("id", 1);
//删除id为1的文档
collection.remove(object);
}

}

posted @ 2014-06-26 15:31  吴伟都  阅读(2548)  评论(0编辑  收藏  举报