java操作mongDB实现多条件查询

来源:互联网 发布:手机淘宝2015旧版本5.6 编辑:程序博客网 时间:2024/05/17 17:41

java操作mongDB实现多条件查询
重点:通过 BasicDBObject 添加多条件,本例中使用DBCursor遍历得到满足条件的对象的name值。

BasicDBObject cond = new BasicDBObject();cond.put("name",user.getName());cond.put("password",user.getPassword());DBCursor dbCursor=table.find(cond);while(dbCursor.hasNext()) {    String ExistName = (String)dbCursor.next().get("name");    return ExistName;}
0 0