1
1
package org .elasticsearch .river .mongodb ;
2
2
3
3
import java .util .ArrayList ;
4
+ import java .util .Collections ;
4
5
import java .util .List ;
5
6
import java .util .NoSuchElementException ;
6
7
import java .util .Set ;
@@ -335,7 +336,6 @@ private String getObjectIdFromOplogEntry(DBObject entry) {
335
336
336
337
private DBObject getOplogFilter (final BSONTimestamp time ) {
337
338
BasicDBObject filter = new BasicDBObject ();
338
- List <DBObject > values2 = new ArrayList <DBObject >();
339
339
340
340
if (time == null ) {
341
341
logger .info ("No known previous slurping time for this collection" );
@@ -346,10 +346,10 @@ private DBObject getOplogFilter(final BSONTimestamp time) {
346
346
if (definition .isMongoGridFS ()) {
347
347
filter .put (MongoDBRiver .OPLOG_NAMESPACE , definition .getMongoOplogNamespace () + MongoDBRiver .GRIDFS_FILES_SUFFIX );
348
348
} else {
349
- values2 . add ( new BasicDBObject ( MongoDBRiver . OPLOG_NAMESPACE , definition . getMongoOplogNamespace ()) );
350
- values2 .add (new BasicDBObject ( MongoDBRiver . OPLOG_NAMESPACE , definition .getMongoDb () + "."
351
- + MongoDBRiver .OPLOG_NAMESPACE_COMMAND ) );
352
- filter .put (MongoDBRiver .MONGODB_OR_OPERATOR , values2 );
349
+ List < String > namespaceFilter = new ArrayList < String >( );
350
+ namespaceFilter .add (definition .getMongoOplogNamespace ());
351
+ namespaceFilter . add ( definition . getMongoDb () + "." + MongoDBRiver .OPLOG_NAMESPACE_COMMAND );
352
+ filter .put (MongoDBRiver .OPLOG_NAMESPACE , new BasicBSONObject ( MongoDBRiver . MONGODB_IN_OPERATOR , namespaceFilter ) );
353
353
}
354
354
if (definition .getMongoOplogFilter ().size () > 0 ) {
355
355
filter .putAll (getMongoFilter ());
@@ -363,20 +363,15 @@ private DBObject getOplogFilter(final BSONTimestamp time) {
363
363
private DBObject getMongoFilter () {
364
364
List <DBObject > filters = new ArrayList <DBObject >();
365
365
List <DBObject > filters2 = new ArrayList <DBObject >();
366
- List <DBObject > filters3 = new ArrayList <DBObject >();
367
- // include delete operation
368
- filters .add (new BasicDBObject (MongoDBRiver .OPLOG_OPERATION , MongoDBRiver .OPLOG_DELETE_OPERATION ));
369
366
370
- // include update, insert in filters3
371
- filters3 .add (new BasicDBObject (MongoDBRiver .OPLOG_OPERATION , MongoDBRiver .OPLOG_UPDATE_OPERATION ));
372
- filters3 .add (new BasicDBObject (MongoDBRiver .OPLOG_OPERATION , MongoDBRiver .OPLOG_INSERT_OPERATION ));
373
-
374
- // include or operation statement in filter2
375
- filters2 .add (new BasicDBObject (MongoDBRiver .MONGODB_OR_OPERATOR , filters3 ));
367
+ List <String > operationFilter = new ArrayList <String >();
368
+ operationFilter .add (MongoDBRiver .OPLOG_DELETE_OPERATION );
369
+ operationFilter .add (MongoDBRiver .OPLOG_UPDATE_OPERATION );
370
+ operationFilter .add (MongoDBRiver .OPLOG_INSERT_OPERATION );
371
+ filters .add (new BasicDBObject (MongoDBRiver .OPLOG_OPERATION , new BasicBSONObject (MongoDBRiver .MONGODB_IN_OPERATOR , operationFilter )));
376
372
377
373
// include custom filter in filters2
378
374
filters2 .add (definition .getMongoOplogFilter ());
379
-
380
375
filters .add (new BasicDBObject (MongoDBRiver .MONGODB_AND_OPERATOR , filters2 ));
381
376
382
377
return new BasicDBObject (MongoDBRiver .MONGODB_OR_OPERATOR , filters );
@@ -396,7 +391,7 @@ private DBCursor oplogCursor(final BSONTimestamp timestampOverride) {
396
391
if (indexFilter .containsField (MongoDBRiver .OPLOG_TIMESTAMP )) {
397
392
options = options | Bytes .QUERYOPTION_OPLOGREPLAY ;
398
393
}
399
- return oplogCollection .find (indexFilter ).sort ( new BasicDBObject ( MongoDBRiver . MONGODB_NATURAL_OPERATOR , 1 )). setOptions (options );
394
+ return oplogCollection .find (indexFilter ).setOptions (options );
400
395
}
401
396
402
397
private void addQueryToStream (final String operation , final BSONTimestamp currentTimestamp , final DBObject update )
0 commit comments