2017-05-24 27 views
0

集約パイプライン実行時にタイムアウトを設定する必要があります。私はMongoDB Javaドライバ3.2を使用しています。MongoDB Java Driverの集約パイプライン実行時にタイムアウトを設定する動作は何ですか?

collection.aggregate(pipeline).maxTime(10, TimeUnit.SECONDS); 

問題は、私は、タイムアウトに達すると、プログラムの動作でどこにも見つけることができないということです。私は、私が使用する必要がコードは次のようであることを知っています。それは例外をスローしましたか?黙って終了し、nullの結果を返しますか?

公式のMongoDBのドキュメントには何も記載されていません(cursor.maxTimeMS()参照)。また、Java APIは特定の動作を参照しません(maxTimeを参照)。

どのように可能ですか?

+0

null iterableを返すことを希望します。テストしたい場合は、すぐにタイムアウトして何が得られるかを確認する時間をごくわずかに入力してください。 –

+0

私は試しました。まったく何もしないようです。タイムアウトが尊重されていないようです:( –

+0

小さいタイムアウトで非ヌル値を返しましたか? –

答えて

0

[OK]を取得しました。集約パイプラインの実行がメソッドmaxTimeで表された時間を超えた場合、com.mongodb.MongoExecutionTimeoutExceptionがスローされます。

例外のスタックトレースが正確に以下の通りです:

com.mongodb.MongoExecutionTimeoutException: operation exceeded time limit 

    at com.mongodb.connection.ProtocolHelper.createSpecialException(ProtocolHelper.java:157) 
    at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:111) 
    at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:114) 
    at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159) 
    at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286) 
    at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:173) 
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:215) 
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:206) 
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:112) 
    at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:227) 
    at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:223) 
    at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:239) 
    at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:212) 
    at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:223) 
    at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:65) 
    at com.mongodb.Mongo.execute(Mongo.java:772) 
    at com.mongodb.Mongo$2.execute(Mongo.java:759) 

はそれがお役に立てば幸いです。

関連する問題