所以情况如此:我有一个程序需要两个大的csv文件,找到差异,然后发送一个数组列表到一个方法,该方法应该用数组中的行更新mongodb。问题是更新正在持续进行。一个包含5000个更新的测试用例需要36分钟。这是正常的吗?用java驱动更新mongodb需要永久吗?
的update(List<String> changes)
- 方法是这样的:
mongoClient = new MongoClient(ip);
db = mongoClient.getDB("foo");
collection = db.getCollection("bar");
//for each line of change
for (String s : changes) {
//splits the csv-lines on ;
String[] fields = s.split(";");
//identifies wich document in the database to be updated
long id = Long.parseLong(fields[0]);
BasicDBObject sq = new BasicDBObject().append("organizationNumber",id);
//creates a new unit-object, that is converted to JSON and then inserted into the database.
Unit u = new Unit(fields);
Gson gson = new Gson();
String jsonObj = gson.toJson(u);
DBObject objectToUpdate = collection.findOne(sq);
DBObject newObject = (DBObject) JSON.parse(jsonObj);
if(objectToUpdate != null){
objectToUpdate.putAll(newObject);
collection.save(objectToUpdate);
}
您是否检查过服务器上的统计信息?看起来应该不会花费那么长时间才能有合理的配置。 – WiredPrairie
@WiredPrairie我刚刚安装了它,我在找什么?你看,这是我第一次使用mongo。 – user2507863
是否将'organizationNumber'编入索引? – WiredPrairie