本文是对mongodb的IN,进行批量查询,查询输出字段为全量
/**
*
* @param key
* 请求字段,如rid
* @param value
* 请求rid的数组
* @return
*/
public int querymuch(String key, String[] value) {
DBObject dbObject = new BasicDBObject();
BasicDBObject query = new BasicDBObject(QueryOperators.IN, value);
dbObject.put(key, query);//key为查询字段,如rid,query为查询条件,如本处的OR查询数组
DBCursor curs = collection.find(dbObject);
try {
while (curs.hasNext()) {
// sb.append("query result-------" + curs.next()+"\n");
curs.next();
}
if (curs.count() > 0) {
_state = 2;
return _state;
} else if (curs.count() == 0) {
_state = 0;
return _state;
}
// return sb.toString();
} catch (Exception e) {
System.err.println("err_rid错误" + key);
e.printStackTrace();
_state = 1;
return _state;
} finally {
curs.close();
}
_state = -1;
return _state;
}
如果需要进行指定字段输出请看下篇博客
如果转载,请注明,转自http://blog.csdn.net/sunqp0208/article/details/41442069