我遇到了我的MongoDB Java驱动程序3.0版的问题。在对几个集合(updateOne,find)执行几个操作之后,我得到一个Command failed with error 8: '24: Too many open files'
错误。我在我的代码oftenly执行的典型操作是下列之一:MongoDB Java API 3.0关闭游标
private Document findFirst(int i) {
FindIterable<Document> cursor = collection.find(new Document("_id", i)).limit(1);
Document exists = null;
for (Document doc : cursor) {
exists = doc;
break;
}
return exists;
}
Document exists = findFirst(integer);
return exists != null ? new MongoDBDocument(collection,exists) : null;
,当我查找了的ID,“会话”未关闭:
Set<Integer> s = new HashSet<>();
for (Document k : collection.find().projection(new Document("_id",1))) { //Fully scan the collection
s.add(Integer.valueOf((String)k.get("_id")));
}
return s;
于是,我看到了在老版API中,查找操作的结果返回了必须关闭的DBCursor。在我看来,在当前的实现中,没有光标被关闭。我看到要实现这个功能的唯一方法是每次关闭MongoClient,但最有可能的是我没有以正确的方式完成任何事情。也许,当我用db.getCollection(name)
检索集合时,必须在对它进行一些操作后以某种方式关闭它:我尝试阅读文档,但没有任何帮助。
服务器的日志返回详细的错误是以下之一:
2016-04-24T13:20:32.839+0200 E STORAGE [conn721] WiredTiger (24) [1461496832:839907][968:0x700000934000], WT_SESSION.create: /data/db/index-1232-7182838846905439482.wt: Too many open files
2016-04-24T13:20:32.840+0200 I COMMAND [conn721] command alledges.$cmd command: createIndexes { createIndexes: "2071853587", indexes: [ { key: { _id: 2071853587 }, name: "_id_2071853587", ns: "alledges.2071853587" } ] } keyUpdates:0 writeConflicts:0 exception: 24: Too many open files code:8 numYields:0 reslen:83 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { W: 1 } } } protocol:op_query 539ms
我在哪里错了?提前致谢。