我可以通过点击上一个jsp文件中的删除按钮
获得真正的IDtry{
MongoClient client = new MongoClient("localhost",27017);
DB db = client.getDB("crawler");
DBCollection collection=db.getCollection("enduser");
DBObject doc=new BasicDBObject();
DBCursor curs = collection.find();
String value = request.getParameter("_id");
collection.remove((DBObject)doc.put("_id",value));
System.out.println(value+"");
}catch(UnknownHostException e){
e.printStackTrace();
}
答案 0 :(得分:1)
value
必须是ObjectId
,而不是String
。试试这个:
collection.remove((DBObject)doc.put("_id", new ObjectId(value)));