gpt4 book ai didi

java - mongoDB:游标 notimeout 设置在 java 客户端中不起作用

转载 作者:IT老高 更新时间:2023-10-28 12:32:12 24 4
gpt4 key购买 nike

我在 java 中为 dbcursor 设置了一个 'notimeout' 选项:

    BasicDBObject nearbyQueries = new BasicDBObject("$gt", 0)
.append("$lte", 2);
DBCursor trueClassInstances = locationsCollection.find(new BasicDBObject("distanceFromHotel", nearbyQueries)).addOption(Bytes.QUERYOPTION_NOTIMEOUT).limit(100000);
double counter = 0;
int currentPresent = 0;
for (DBObject instance : trueClassInstances) {

...
}

即使我设置了这个选项,也会抛出这个异常:

Exception in thread "main" com.mongodb.MongoCursorNotFoundException: Query failed with error code -5 and error message 'Cursor 1876954464377 not found on server XXXXXX:27017' on server XXXXXXXX:27017
at com.mongodb.connection.GetMoreProtocol.receiveMessage(GetMoreProtocol.java:115)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:68)
at com.mongodb.connection.GetMoreProtocol.execute(GetMoreProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
at com.mongodb.connection.DefaultServerConnection.getMore(DefaultServerConnection.java:194)
at com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:197)
at com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:93)
at com.mongodb.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:46)
at com.mongodb.DBCursor.hasNext(DBCursor.java:152)
at locationExtraction.DistanceClassification.FeatureAnalyzer.main(FeatureAnalyzer.java:27)

FeatureAnalyzer.java:27 是 for 循环行。

此问题出现在其他具有类似设置的项目中...

我做错了什么?也许我选择“for”循环而不是这种迭代会导致这种奇怪的行为?

while(cursor.hasNext())
{
DBObject next = cursor.next();
}

谢谢

最佳答案

您似乎无法在时限内处理每个批处理。尝试减少批处理大小,以便在时间用完之前消耗每个批处理。这应该会有所帮助。
cursor.addOption(com.mongodb.Bytes.QUERYOPTION_NOTIMEOUT).batchSize(100)

关于java - mongoDB:游标 notimeout 设置在 java 客户端中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31948124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com