- 论坛徽章:
- 0
|
//获取collection
DBCollection investorColl = db.getCollection("investor" + exchangeStr.trim().toLowerCase());
......
//查询数据
DBCursor investorCur = investorColl.find(query);
//循环处理查询出来的数据
while(investorCur.hasNext()){
BasicDBObject investor = (BasicDBObject) investorCur.next();
............
if("01111923".equals(investorid)){
System.out.println(investor);
}
//使用相同的查询条件,更新同一条记录
investorColl.update(query, new BasicDBObject("$set",updateValue));
}
会发现调试信息会输出同一条数据两次,也就是说会更新同一条记录两次,其中第一次是未更新的数据,第二次是更新之后的数据。
实际上数据库中是没有重复的数据的,在循环过程中,程序应该是从数据库中查询到同一条记录两次,一次是更新前的,一次是更新后的。调试了一天不知道为什么。有遇到相同情况的吗?
|
|