signature:
public class JsonScanner { /** * Finds and returns the next complete token from this scanner . If scanner reached the end of the source , it will return a token with
 * { @ code JSONTokenType . END _ OF _ FILE } type .
 * @ return The next token .
 * @ throws JsonParseException if source is invalid . */
public JsonToken nextToken ( ) { } }

implementation: int c = buffer . read ( ) ; while ( c != - 1 && Character . isWhitespace ( c ) ) { c = buffer . read ( ) ; } if ( c == - 1 ) { return new JsonToken ( JsonTokenType . END_OF_FILE , "<eof>" ) ; } switch ( c ) { case '{' : return new JsonToken ( JsonTokenType . BEGIN_OBJECT , "{" ) ; case '}' : return new JsonToken ( JsonTokenType . END_OBJECT , "}" ) ; case '[' : return new JsonToken ( JsonTokenType . BEGIN_ARRAY , "[" ) ; case ']' : return new JsonToken ( JsonTokenType . END_ARRAY , "]" ) ; case '(' : return new JsonToken ( JsonTokenType . LEFT_PAREN , "(" ) ; case ')' : return new JsonToken ( JsonTokenType . RIGHT_PAREN , ")" ) ; case ':' : return new JsonToken ( JsonTokenType . COLON , ":" ) ; case ',' : return new JsonToken ( JsonTokenType . COMMA , "," ) ; case '\'' : case '"' : return scanString ( ( char ) c ) ; case '/' : return scanRegularExpression ( ) ; default : if ( c == '-' || Character . isDigit ( c ) ) { return scanNumber ( ( char ) c ) ; } else if ( c == '$' || c == '_' || Character . isLetter ( c ) ) { return scanUnquotedString ( ( char ) c ) ; } else { int position = buffer . getPosition ( ) ; buffer . unread ( c ) ; throw new JsonParseException ( "Invalid JSON input. Position: %d. Character: '%c'." , position , c ) ; } }


signature:
public class JsonScanner { /** * Reads { @ code RegularExpressionToken } from source . The following variants of lexemes are possible :
 * < pre >
 * / pattern /
 * / \ ( pattern \ ) /
 * / pattern / ims
 * < / pre >
 * Options can include ' i ' , ' m ' , ' x ' , ' s '
 * @ return The regular expression token .
 * @ throws JsonParseException if regular expression representation is not valid . */
private JsonToken scanRegularExpression ( ) { } }

implementation: StringBuilder patternBuilder = new StringBuilder ( ) ; StringBuilder optionsBuilder = new StringBuilder ( ) ; RegularExpressionState state = RegularExpressionState . IN_PATTERN ; while ( true ) { int c = buffer . read ( ) ; switch ( state ) { case IN_PATTERN : switch ( c ) { case - 1 : state = RegularExpressionState . INVALID ; break ; case '/' : state = RegularExpressionState . IN_OPTIONS ; break ; case '\\' : state = RegularExpressionState . IN_ESCAPE_SEQUENCE ; break ; default : state = RegularExpressionState . IN_PATTERN ; break ; } break ; case IN_ESCAPE_SEQUENCE : state = RegularExpressionState . IN_PATTERN ; break ; case IN_OPTIONS : switch ( c ) { case 'i' : case 'm' : case 'x' : case 's' : state = RegularExpressionState . IN_OPTIONS ; break ; case ',' : case '}' : case ']' : case ')' : case - 1 : state = RegularExpressionState . DONE ; break ; default : if ( Character . isWhitespace ( c ) ) { state = RegularExpressionState . DONE ; } else { state = RegularExpressionState . INVALID ; } break ; } break ; default : break ; } switch ( state ) { case DONE : buffer . unread ( c ) ; BsonRegularExpression regex = new BsonRegularExpression ( patternBuilder . toString ( ) , optionsBuilder . toString ( ) ) ; return new JsonToken ( JsonTokenType . REGULAR_EXPRESSION , regex ) ; case INVALID : throw new JsonParseException ( "Invalid JSON regular expression. Position: %d." , buffer . getPosition ( ) ) ; default : switch ( state ) { case IN_OPTIONS : if ( c != '/' ) { optionsBuilder . append ( ( char ) c ) ; } break ; default : patternBuilder . append ( ( char ) c ) ; break ; } } }


signature:
public class JsonScanner { /** * Reads { @ code StringToken } from source .
 * @ return The string token . */
private JsonToken scanUnquotedString ( final char firstChar ) { } }

implementation: StringBuilder sb = new StringBuilder ( ) ; sb . append ( firstChar ) ; int c = buffer . read ( ) ; while ( c == '$' || c == '_' || Character . isLetterOrDigit ( c ) ) { sb . append ( ( char ) c ) ; c = buffer . read ( ) ; } buffer . unread ( c ) ; String lexeme = sb . toString ( ) ; return new JsonToken ( JsonTokenType . UNQUOTED_STRING , lexeme ) ;


signature:
public class JsonScanner { /** * CHECKSTYLE : OFF */
private JsonToken scanNumber ( final char firstChar ) { } }

implementation: int c = firstChar ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( firstChar ) ; NumberState state ; switch ( c ) { case '-' : state = NumberState . SAW_LEADING_MINUS ; break ; case '0' : state = NumberState . SAW_LEADING_ZERO ; break ; default : state = NumberState . SAW_INTEGER_DIGITS ; break ; } JsonTokenType type = JsonTokenType . INT64 ; while ( true ) { c = buffer . read ( ) ; switch ( state ) { case SAW_LEADING_MINUS : switch ( c ) { case '0' : state = NumberState . SAW_LEADING_ZERO ; break ; case 'I' : state = NumberState . SAW_MINUS_I ; break ; default : if ( Character . isDigit ( c ) ) { state = NumberState . SAW_INTEGER_DIGITS ; } else { state = NumberState . INVALID ; } break ; } break ; case SAW_LEADING_ZERO : switch ( c ) { case '.' : state = NumberState . SAW_DECIMAL_POINT ; break ; case 'e' : case 'E' : state = NumberState . SAW_EXPONENT_LETTER ; break ; case ',' : case '}' : case ']' : case ')' : case - 1 : state = NumberState . DONE ; break ; default : if ( Character . isDigit ( c ) ) { state = NumberState . SAW_INTEGER_DIGITS ; } else if ( Character . isWhitespace ( c ) ) { state = NumberState . DONE ; } else { state = NumberState . INVALID ; } break ; } break ; case SAW_INTEGER_DIGITS : switch ( c ) { case '.' : state = NumberState . SAW_DECIMAL_POINT ; break ; case 'e' : case 'E' : state = NumberState . SAW_EXPONENT_LETTER ; break ; case ',' : case '}' : case ']' : case ')' : case - 1 : state = NumberState . DONE ; break ; default : if ( Character . isDigit ( c ) ) { state = NumberState . SAW_INTEGER_DIGITS ; } else if ( Character . isWhitespace ( c ) ) { state = NumberState . DONE ; } else { state = NumberState . INVALID ; } break ; } break ; case SAW_DECIMAL_POINT : type = JsonTokenType . DOUBLE ; if ( Character . isDigit ( c ) ) { state = NumberState . SAW_FRACTION_DIGITS ; } else { state = NumberState . INVALID ; } break ; case SAW_FRACTION_DIGITS : switch ( c ) { case 'e' : case 'E' : state = NumberState . SAW_EXPONENT_LETTER ; break ; case ',' : case '}' : case ']' : case ')' : case - 1 : state = NumberState . DONE ; break ; default : if ( Character . isDigit ( c ) ) { state = NumberState . SAW_FRACTION_DIGITS ; } else if ( Character . isWhitespace ( c ) ) { state = NumberState . DONE ; } else { state = NumberState . INVALID ; } break ; } break ; case SAW_EXPONENT_LETTER : type = JsonTokenType . DOUBLE ; switch ( c ) { case '+' : case '-' : state = NumberState . SAW_EXPONENT_SIGN ; break ; default : if ( Character . isDigit ( c ) ) { state = NumberState . SAW_EXPONENT_DIGITS ; } else { state = NumberState . INVALID ; } break ; } break ; case SAW_EXPONENT_SIGN : if ( Character . isDigit ( c ) ) { state = NumberState . SAW_EXPONENT_DIGITS ; } else { state = NumberState . INVALID ; } break ; case SAW_EXPONENT_DIGITS : switch ( c ) { case ',' : case '}' : case ']' : case ')' : state = NumberState . DONE ; break ; default : if ( Character . isDigit ( c ) ) { state = NumberState . SAW_EXPONENT_DIGITS ; } else if ( Character . isWhitespace ( c ) ) { state = NumberState . DONE ; } else { state = NumberState . INVALID ; } break ; } break ; case SAW_MINUS_I : boolean sawMinusInfinity = true ; char [ ] nfinity = new char [ ] { 'n' , 'f' , 'i' , 'n' , 'i' , 't' , 'y' } ; for ( int i = 0 ; i < nfinity . length ; i ++ ) { if ( c != nfinity [ i ] ) { sawMinusInfinity = false ; break ; } sb . append ( ( char ) c ) ; c = buffer . read ( ) ; } if ( sawMinusInfinity ) { type = JsonTokenType . DOUBLE ; switch ( c ) { case ',' : case '}' : case ']' : case ')' : case - 1 : state = NumberState . DONE ; break ; default : if ( Character . isWhitespace ( c ) ) { state = NumberState . DONE ; } else { state = NumberState . INVALID ; } break ; } } else { state = NumberState . INVALID ; } break ; default : } switch ( state ) { case INVALID : throw new JsonParseException ( "Invalid JSON number" ) ; case DONE : buffer . unread ( c ) ; String lexeme = sb . toString ( ) ; if ( type == JsonTokenType . DOUBLE ) { return new JsonToken ( JsonTokenType . DOUBLE , Double . parseDouble ( lexeme ) ) ; } else { long value = Long . parseLong ( lexeme ) ; if ( value < Integer . MIN_VALUE || value > Integer . MAX_VALUE ) { return new JsonToken ( JsonTokenType . INT64 , value ) ; } else { return new JsonToken ( JsonTokenType . INT32 , ( int ) value ) ; } } default : sb . append ( ( char ) c ) ; } }


signature:
public class JsonScanner { /** * CHECKSTYLE : OFF */
private JsonToken scanString ( final char quoteCharacter ) { } }

implementation: StringBuilder sb = new StringBuilder ( ) ; while ( true ) { int c = buffer . read ( ) ; switch ( c ) { case '\\' : c = buffer . read ( ) ; switch ( c ) { case '\'' : sb . append ( '\'' ) ; break ; case '"' : sb . append ( '"' ) ; break ; case '\\' : sb . append ( '\\' ) ; break ; case '/' : sb . append ( '/' ) ; break ; case 'b' : sb . append ( '\b' ) ; break ; case 'f' : sb . append ( '\f' ) ; break ; case 'n' : sb . append ( '\n' ) ; break ; case 'r' : sb . append ( '\r' ) ; break ; case 't' : sb . append ( '\t' ) ; break ; case 'u' : int u1 = buffer . read ( ) ; int u2 = buffer . read ( ) ; int u3 = buffer . read ( ) ; int u4 = buffer . read ( ) ; if ( u4 != - 1 ) { String hex = new String ( new char [ ] { ( char ) u1 , ( char ) u2 , ( char ) u3 , ( char ) u4 } ) ; sb . append ( ( char ) Integer . parseInt ( hex , 16 ) ) ; } break ; default : throw new JsonParseException ( "Invalid escape sequence in JSON string '\\%c'." , c ) ; } break ; default : if ( c == quoteCharacter ) { return new JsonToken ( JsonTokenType . STRING , sb . toString ( ) ) ; } if ( c != - 1 ) { sb . append ( ( char ) c ) ; } } if ( c == - 1 ) { throw new JsonParseException ( "End of file in JSON string." ) ; } }


signature:
public class FsyncUnlockOperation { /** * Unlocks the MongoDB server , allowing write operations to go through .
 * @ param binding the binding to execute in the context of
 * @ return the result of the operation
 * @ deprecated use { @ link # execute ( ReadBinding ) } instead . */
@ Deprecated @ Override public BsonDocument execute ( final WriteBinding binding ) { } }

implementation: return withConnection ( binding , new CallableWithConnection < BsonDocument > ( ) { @ Override public BsonDocument call ( final Connection connection ) { if ( serverIsAtLeastVersionThreeDotTwo ( connection . getDescription ( ) ) ) { return executeCommand ( binding , "admin" , FSYNC_UNLOCK_COMMAND , connection ) ; } else { return queryUnlock ( connection ) ; } } } ) ;


signature:
public class QuickTourAdmin { /** * Run this main method to see the output of this quick example .
 * @ param args takes an optional single argument for the connection string
 * @ throws InterruptedException if a latch is interrupted */
public static void main ( final String [ ] args ) throws InterruptedException { } }

implementation:
MongoClient mongoClient ; if ( args . length == 0 ) { // connect to the local database server
mongoClient = MongoClients . create ( ) ; } else { mongoClient = MongoClients . create ( args [ 0 ] ) ; } // get handle to " mydb " database
MongoDatabase database = mongoClient . getDatabase ( "mydb" ) ; // get a handle to the " test " collection
MongoCollection < Document > collection = database . getCollection ( "test" ) ; final CountDownLatch dropLatch = new CountDownLatch ( 1 ) ; collection . drop ( new SingleResultCallback < Void > ( ) { @ Override public void onResult ( final Void result , final Throwable t ) { dropLatch . countDown ( ) ; } } ) ; dropLatch . await ( ) ; // getting a list of databases
SingleResultCallback < Void > callbackWhenFinished = new SingleResultCallback < Void > ( ) { @ Override public void onResult ( final Void result , final Throwable t ) { System . out . println ( "Operation Finished!" ) ; } } ; mongoClient . listDatabaseNames ( ) . forEach ( new Block < String > ( ) { @ Override public void apply ( final String s ) { System . out . println ( s ) ; } } , callbackWhenFinished ) ; // drop a database
mongoClient . getDatabase ( "databaseToBeDropped" ) . drop ( callbackWhenFinished ) ; // create a collection
database . createCollection ( "cappedCollection" , new CreateCollectionOptions ( ) . capped ( true ) . sizeInBytes ( 0x100000 ) , callbackWhenFinished ) ; database . listCollectionNames ( ) . forEach ( new Block < String > ( ) { @ Override public void apply ( final String databaseName ) { System . out . println ( databaseName ) ; } } , callbackWhenFinished ) ; // drop a collection :
collection . drop ( callbackWhenFinished ) ; // create an ascending index on the " i " field
collection . createIndex ( Indexes . ascending ( "i" ) , new SingleResultCallback < String > ( ) { @ Override public void onResult ( final String result , final Throwable t ) { System . out . println ( "Operation finished" ) ; } } ) ; // list the indexes on the collection
Block < Document > printDocumentBlock = new Block < Document > ( ) { @ Override public void apply ( final Document document ) { System . out . println ( document . toJson ( ) ) ; } } ; collection . listIndexes ( ) . forEach ( printDocumentBlock , callbackWhenFinished ) ; // create a text index on the " content " field
collection . createIndex ( Indexes . text ( "content" ) , new SingleResultCallback < String > ( ) { @ Override public void onResult ( final String result , final Throwable t ) { System . out . println ( "Operation finished" ) ; } } ) ; collection . insertOne ( new Document ( "_id" , 0 ) . append ( "content" , "textual content" ) , callbackWhenFinished ) ; collection . insertOne ( new Document ( "_id" , 1 ) . append ( "content" , "additional content" ) , callbackWhenFinished ) ; collection . insertOne ( new Document ( "_id" , 2 ) . append ( "content" , "irrelevant content" ) , callbackWhenFinished ) ; // Find using the text index
collection . countDocuments ( text ( "textual content -irrelevant" ) , new SingleResultCallback < Long > ( ) { @ Override public void onResult ( final Long matchCount , final Throwable t ) { System . out . println ( "Text search matches: " + matchCount ) ; } } ) ; // Find using the $ language operator
Bson textSearch = text ( "textual content -irrelevant" , new TextSearchOptions ( ) . language ( "english" ) ) ; collection . countDocuments ( textSearch , new SingleResultCallback < Long > ( ) { @ Override public void onResult ( final Long matchCount , final Throwable t ) { System . out . println ( "Text search matches (english): " + matchCount ) ; } } ) ; // Find the highest scoring match
Document projection = new Document ( "score" , new Document ( "$meta" , "textScore" ) ) ; collection . find ( textSearch ) . projection ( projection ) . first ( new SingleResultCallback < Document > ( ) { @ Override public void onResult ( final Document highest , final Throwable t ) { System . out . println ( "Highest scoring document: " + highest . toJson ( ) ) ; } } ) ; // Run a command
database . runCommand ( new Document ( "buildInfo" , 1 ) , new SingleResultCallback < Document > ( ) { @ Override public void onResult ( final Document buildInfo , final Throwable t ) { System . out . println ( buildInfo ) ; } } ) ; // release resources
database . drop ( callbackWhenFinished ) ; mongoClient . close ( ) ;


signature:
public class ReadPreference { /** * Chooses the servers from the given cluster than match this read preference .
 * @ param clusterDescription the cluster description
 * @ return a list of matching server descriptions , which may be empty but may not be null */
public final List < ServerDescription > choose ( final ClusterDescription clusterDescription ) { } }

implementation: switch ( clusterDescription . getType ( ) ) { case REPLICA_SET : return chooseForReplicaSet ( clusterDescription ) ; case SHARDED : case STANDALONE : return chooseForNonReplicaSet ( clusterDescription ) ; case UNKNOWN : return Collections . emptyList ( ) ; default : throw new UnsupportedOperationException ( "Unsupported cluster type: " + clusterDescription . getType ( ) ) ; }


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to the primary if available , otherwise to a secondary .
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads primary if available .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static ReadPreference primaryPreferred ( final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new PrimaryPreferredReadPreference ( Collections . < TagSet > emptyList ( ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to a secondary that is less stale than the given maximum .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads secondary .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static ReadPreference secondary ( final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new SecondaryReadPreference ( Collections . < TagSet > emptyList ( ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to a secondary that is less stale than the given maximumm if one is available ,
 * otherwise to the primary .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads secondary if available , otherwise from primary .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static ReadPreference secondaryPreferred ( final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new SecondaryPreferredReadPreference ( Collections . < TagSet > emptyList ( ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to a primary or a secondary that is less stale than the given maximum .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads nearest
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static ReadPreference nearest ( final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new NearestReadPreference ( Collections . < TagSet > emptyList ( ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to the primary if available , otherwise to a secondary with the given set of tags
 * that is less stale than the given maximum .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSet the set of tags to limit the list of secondaries to .
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads primary if available , otherwise a secondary respective of tags . \
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference primaryPreferred ( final TagSet tagSet , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new PrimaryPreferredReadPreference ( singletonList ( tagSet ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to a secondary with the given set of tags that is less stale than the given maximum .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSet the set of tags to limit the list of secondaries to
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads secondary respective of tags .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference secondary ( final TagSet tagSet , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new SecondaryReadPreference ( singletonList ( tagSet ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to a secondary with the given set of tags that is less stale than the given maximum ,
 * or the primary is none are available .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSet the set of tags to limit the list of secondaries to
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads secondary if available respective of tags , otherwise from primary irrespective of tags .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference secondaryPreferred ( final TagSet tagSet , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new SecondaryPreferredReadPreference ( singletonList ( tagSet ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to the primary or a secondary with the given set of tags that is less stale than the
 * given maximum .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSet the set of tags to limit the list of secondaries to
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads nearest node respective of tags .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference nearest ( final TagSet tagSet , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new NearestReadPreference ( singletonList ( tagSet ) , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to the primary if available , otherwise to a secondary with one of the given sets of tags
 * that is less stale than the given maximum .
 * The driver will look for a secondary with each tag set in the given list , stopping after one is found ,
 * or failing if no secondary can be found that matches any of the tag sets in the list .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSetList the list of tag sets to limit the list of secondaries to
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads primary if available , otherwise a secondary respective of tags .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference primaryPreferred ( final List < TagSet > tagSetList , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new PrimaryPreferredReadPreference ( tagSetList , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to a secondary with one of the given sets of tags that is less stale than
 * the given maximum .
 * The driver will look for a secondary with each tag set in the given list , stopping after one is found ,
 * or failing if no secondary can be found that matches any of the tag sets in the list .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSetList the list of tag sets to limit the list of secondaries to
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads secondary respective of tags .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference secondary ( final List < TagSet > tagSetList , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new SecondaryReadPreference ( tagSetList , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to a secondary with one of the given sets of tags that is less stale than
 * the given maximum .
 * The driver will look for a secondary with each tag set in the given list , stopping after one is found ,
 * or the primary if none are available .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSetList the list of tag sets to limit the list of secondaries to
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads secondary if available respective of tags , otherwise from primary irrespective of tags .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference secondaryPreferred ( final List < TagSet > tagSetList , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new SecondaryPreferredReadPreference ( tagSetList , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Gets a read preference that forces reads to the primary or a secondary with one of the given sets of tags that is less stale than
 * the given maximum .
 * The driver will look for a secondary with each tag set in the given list , stopping after one is found ,
 * or the primary if none are available .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param tagSetList the list of tag sets to limit the list of secondaries to
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return ReadPreference which reads nearest node respective of tags .
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference nearest ( final List < TagSet > tagSetList , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return new NearestReadPreference ( tagSetList , maxStaleness , timeUnit ) ;


signature:
public class ReadPreference { /** * Creates a read preference from the given read preference name .
 * @ param name the name of the read preference
 * @ return the read preference */
public static ReadPreference valueOf ( final String name ) { } }

implementation: notNull ( "name" , name ) ; String nameToCheck = name . toLowerCase ( ) ; if ( nameToCheck . equals ( PRIMARY . getName ( ) . toLowerCase ( ) ) ) { return PRIMARY ; } if ( nameToCheck . equals ( SECONDARY . getName ( ) . toLowerCase ( ) ) ) { return SECONDARY ; } if ( nameToCheck . equals ( SECONDARY_PREFERRED . getName ( ) . toLowerCase ( ) ) ) { return SECONDARY_PREFERRED ; } if ( nameToCheck . equals ( PRIMARY_PREFERRED . getName ( ) . toLowerCase ( ) ) ) { return PRIMARY_PREFERRED ; } if ( nameToCheck . equals ( NEAREST . getName ( ) . toLowerCase ( ) ) ) { return NEAREST ; } throw new IllegalArgumentException ( "No match for read preference of " + name ) ;


signature:
public class ReadPreference { /** * Creates a taggable read preference from the given read preference name and list of tag sets .
 * @ param name the name of the read preference
 * @ param tagSetList the list of tag sets
 * @ return the taggable read preference
 * @ since 2.13 */
public static TaggableReadPreference valueOf ( final String name , final List < TagSet > tagSetList ) { } }

implementation: return valueOf ( name , tagSetList , null , MILLISECONDS ) ;


signature:
public class ReadPreference { /** * Creates a taggable read preference from the given read preference name , list of tag sets , and max allowable staleness of secondaries .
 * The driver estimates the staleness of each secondary , based on lastWriteDate values provided in server isMaster responses ,
 * and selects only those secondaries whose staleness is less than or equal to maxStaleness .
 * @ param name the name of the read preference
 * @ param tagSetList the list of tag sets
 * @ param maxStaleness the max allowable staleness of secondaries . The minimum value is either 90 seconds , or the heartbeat frequency
 * plus 10 seconds , whichever is greatest .
 * @ param timeUnit the time unit of maxStaleness
 * @ return the taggable read preference
 * @ since 3.4
 * @ see TaggableReadPreference # getMaxStaleness ( TimeUnit ) */
public static TaggableReadPreference valueOf ( final String name , final List < TagSet > tagSetList , final long maxStaleness , final TimeUnit timeUnit ) { } }

implementation: return valueOf ( name , tagSetList , ( Long ) maxStaleness , timeUnit ) ;


signature:
public class BufferHolder { /** * Fill with zeros the remaining of the supplied buffer . This method does
 * not change the buffer position .
 * Typically used for security reasons , with buffers that contains
 * now - unused plaintext . */
public void zeroRemaining ( ) { } }

implementation: ( ( Buffer ) buffer ) . mark ( ) ; buffer . put ( ZEROS , 0 , buffer . remaining ( ) ) ; ( ( Buffer ) buffer ) . reset ( ) ;


signature:
public class BufferHolder { /** * Fill the buffer with zeros . This method does not change the buffer position .
 * Typically used for security reasons , with buffers that contains
 * now - unused plaintext . */
public void zero ( ) { } }

implementation: ( ( Buffer ) buffer ) . mark ( ) ; ( ( Buffer ) buffer ) . position ( 0 ) ; buffer . put ( ZEROS , 0 , buffer . remaining ( ) ) ; ( ( Buffer ) buffer ) . reset ( ) ;


signature:
public class Bits { /** * Reads bytes from the input stream and puts them into the given byte buffer . The equivalent of calling
 * { @ link # readFully ( java . io . InputStream , byte [ ] , int , int ) } with an offset of zero and a length equal to the length of the buffer .
 * @ param inputStream the input stream to read from
 * @ param buffer the buffer into which the data is read .
 * @ throws IOException if there ' s an error reading from the { @ code inputStream } */
public static void readFully ( final InputStream inputStream , final byte [ ] buffer ) throws IOException { } }

implementation: readFully ( inputStream , buffer , buffer . length ) ;


signature:
public class Bits { /** * Reads bytes from the input stream and puts them into the given byte buffer .
 * @ param inputStream the input stream to read from
 * @ param buffer the buffer into which the data is read .
 * @ param offset the start offset in array { @ code buffer } at which the data is written .
 * @ param length the maximum number of bytes to read .
 * @ throws IOException if there ' s an error reading from the { @ code inputStream }
 * @ see java . io . InputStream # read ( byte [ ] , int , int ) */
public static void readFully ( final InputStream inputStream , final byte [ ] buffer , final int offset , final int length ) throws IOException { } }

implementation: if ( buffer . length < length + offset ) { throw new IllegalArgumentException ( "Buffer is too small" ) ; } int arrayOffset = offset ; int bytesToRead = length ; while ( bytesToRead > 0 ) { int bytesRead = inputStream . read ( buffer , arrayOffset , bytesToRead ) ; if ( bytesRead < 0 ) { throw new EOFException ( ) ; } bytesToRead -= bytesRead ; arrayOffset += bytesRead ; }


signature:
public class Bits { /** * Reads and returns a single integer value from the input stream .
 * @ param inputStream the input stream to read from
 * @ param buffer the buffer to write the input stream bytes into
 * @ return the integer value
 * @ throws IOException if there ' s an error reading from the { @ code inputStream } */
public static int readInt ( final InputStream inputStream , final byte [ ] buffer ) throws IOException { } }

implementation: readFully ( inputStream , buffer , 4 ) ; return readInt ( buffer ) ;


signature:
public class Bits { /** * Reads and returns a single integer value from the buffer .
 * @ param buffer the buffer to read from
 * @ param offset the position to start reading from the buffer
 * @ return the integer value */
public static int readInt ( final byte [ ] buffer , final int offset ) { } }

implementation: int x = 0 ; x |= ( 0xFF & buffer [ offset + 0 ] ) << 0 ; x |= ( 0xFF & buffer [ offset + 1 ] ) << 8 ; x |= ( 0xFF & buffer [ offset + 2 ] ) << 16 ; x |= ( 0xFF & buffer [ offset + 3 ] ) << 24 ; return x ;


signature:
public class Bits { /** * Reads and returns a single big - endian integer value
 * @ param buffer the buffer to read from
 * @ param offset the position to start reading from the buffer
 * @ return the integer value */
public static int readIntBE ( final byte [ ] buffer , final int offset ) { } }

implementation: int x = 0 ; x |= ( 0xFF & buffer [ offset + 0 ] ) << 24 ; x |= ( 0xFF & buffer [ offset + 1 ] ) << 16 ; x |= ( 0xFF & buffer [ offset + 2 ] ) << 8 ; x |= ( 0xFF & buffer [ offset + 3 ] ) << 0 ; return x ;


signature:
public class Bits { /** * Reads and returns a single long value from the input stream .
 * @ param inputStream the input stream to read from
 * @ param buffer the buffer to write the input stream bytes into
 * @ return the long value
 * @ throws IOException if there ' s an error reading from the { @ code inputStream } */
public static long readLong ( final InputStream inputStream , final byte [ ] buffer ) throws IOException { } }

implementation: readFully ( inputStream , buffer , 8 ) ; return readLong ( buffer ) ;


signature:
public class ConnectionString { /** * even for options which multiple values , e . g . readPreferenceTags */
private Map < String , List < String > > combineOptionsMaps ( final Map < String , List < String > > txtRecordsOptionsMap , final Map < String , List < String > > connectionStringOptionsMap ) { } }

implementation: Map < String , List < String > > combinedOptionsMaps = new HashMap < String , List < String > > ( txtRecordsOptionsMap ) ; for ( Map . Entry < String , List < String > > entry : connectionStringOptionsMap . entrySet ( ) ) { combinedOptionsMaps . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return combinedOptionsMaps ;


signature:
public class ConnectionString { /** * Gets the credentials in an immutable list . The list will be empty if no credentials were specified in the connection string .
 * @ return the credentials in an immutable list
 * @ deprecated Prefer { @ link # getCredential ( ) } */
@ Deprecated public List < MongoCredential > getCredentialList ( ) { } }

implementation: return credential != null ? singletonList ( credential ) : Collections . < MongoCredential > emptyList ( ) ;


signature:
public class BaseCluster { /** * gets a random server that still exists in the cluster . Returns null if there are none . */
private ClusterableServer getRandomServer ( final List < ServerDescription > serverDescriptions ) { } }

implementation: while ( ! serverDescriptions . isEmpty ( ) ) { int serverPos = getRandom ( ) . nextInt ( serverDescriptions . size ( ) ) ; ClusterableServer server = getServer ( serverDescriptions . get ( serverPos ) . getAddress ( ) ) ; if ( server != null ) { return server ; } else { serverDescriptions . remove ( serverPos ) ; } } return null ;


signature:
public class BaseCluster { /** * initialValue ( ) method . */
private Random getRandom ( ) { } }

implementation: Random result = random . get ( ) ; if ( result == null ) { result = new Random ( ) ; random . set ( result ) ; } return result ;


signature:
public class MongoClients { /** * Creates a new client with the given client settings .
 * < p > Note : Intended for driver and library authors to associate extra driver metadata with the connections . < / p >
 * @ param settings the settings
 * @ param mongoDriverInformation any driver information to associate with the MongoClient
 * @ return the client
 * @ since 3.4
 * @ deprecated use { @ link # create ( com . mongodb . MongoClientSettings , MongoDriverInformation ) } instead */
@ Deprecated public static MongoClient create ( final MongoClientSettings settings , @ Nullable final MongoDriverInformation mongoDriverInformation ) { } }

implementation: return create ( settings , mongoDriverInformation , null ) ;


signature:
public class MongoClients { /** * Create a new client with the given connection string .
 * < p > Note : Intended for driver and library authors to associate extra driver metadata with the connections . < / p >
 * @ param connectionString the settings
 * @ param mongoDriverInformation any driver information to associate with the MongoClient
 * @ return the client
 * @ throws IllegalArgumentException if the connection string ' s stream type is not one of " netty " or " nio2"
 * @ see MongoClients # create ( ConnectionString ) */
public static MongoClient create ( final ConnectionString connectionString , @ Nullable final MongoDriverInformation mongoDriverInformation ) { } }

implementation: return create ( MongoClientSettings . builder ( ) . applyConnectionString ( connectionString ) . build ( ) , mongoDriverInformation , connectionString . getStreamType ( ) ) ;


signature:
public class MongoClients { /** * Creates a new client with the given client settings .
 * < p > Note : Intended for driver and library authors to associate extra driver metadata with the connections . < / p >
 * @ param settings the settings
 * @ param mongoDriverInformation any driver information to associate with the MongoClient
 * @ return the client
 * @ since 3.7 */
public static MongoClient create ( final com . mongodb . MongoClientSettings settings , @ Nullable final MongoDriverInformation mongoDriverInformation ) { } }

implementation: return create ( MongoClientSettings . createFromClientSettings ( settings ) , mongoDriverInformation , null ) ;


signature:
public class BasicDBList { /** * Copies this instance into a new Object .
 * @ return a new BasicDBList with the same values as this instance */
public Object copy ( ) { } }

implementation:
// copy field values into new object
BasicDBList newobj = new BasicDBList ( ) ; // need to clone the sub obj
for ( int i = 0 ; i < size ( ) ; ++ i ) { Object val = get ( i ) ; if ( val instanceof BasicDBObject ) { val = ( ( BasicDBObject ) val ) . copy ( ) ; } else if ( val instanceof BasicDBList ) { val = ( ( BasicDBList ) val ) . copy ( ) ; } newobj . add ( val ) ; } return newobj ;


signature:
public class ClassModel { /** * Creates a new Class Model builder instance using reflection .
 * @ param type the POJO class to reflect and configure the builder with .
 * @ param < S > the type of the class
 * @ return a new Class Model builder instance using reflection on the { @ code clazz } . */
public static < S > ClassModelBuilder < S > builder ( final Class < S > type ) { } }

implementation: return new ClassModelBuilder < S > ( type ) ;


signature:
public class ClassModel { /** * Gets a { @ link PropertyModel } by the property name .
 * @ param propertyName the PropertyModel ' s property name
 * @ return the PropertyModel or null if the property is not found */
public PropertyModel < ? > getPropertyModel ( final String propertyName ) { } }

implementation: for ( PropertyModel < ? > propertyModel : propertyModels ) { if ( propertyModel . getName ( ) . equals ( propertyName ) ) { return propertyModel ; } } return null ;


signature:
public class FindOneAndReplaceOptions { /** * Sets the maximum execution time on the server for this operation .
 * @ param maxTime the max time
 * @ param timeUnit the time unit , which may not be null
 * @ return this */
public FindOneAndReplaceOptions maxTime ( final long maxTime , final TimeUnit timeUnit ) { } }

implementation: notNull ( "timeUnit" , timeUnit ) ; this . maxTimeMS = MILLISECONDS . convert ( maxTime , timeUnit ) ; return this ;


signature:
public class MongoClientFactory { /** * This implementation will create instances of { @ link MongoClient } based on a connection string conforming to the format specified in
 * { @ link MongoClientURI } .
 * < p > The connection string is specified in one of two ways : < / p >
 * < ul >
 * < li > As the { @ code String } value of a property in the { @ code environment } parameter with a key of { @ code " connectionString " } < / li >
 * < li > As the { @ code String } value of a { @ link RefAddr } with type { @ code " connectionString " } in an { @ code obj } parameter
 * of type { @ link Reference } < / li >
 * < / ul >
 * Specification of the connection string in the { @ code environment } parameter takes precedence over specification in the { @ code obj }
 * parameter . The { @ code name } and { @ code nameCtx } parameters are ignored .
 * If a non - empty connection string is not specified in either of these two ways , a { @ link MongoException } is thrown .
 * @ return an instance of { @ link MongoClient } based on the specified connection string
 * @ throws MongoException
 * Note : Not all options that can be specified via { @ link com . mongodb . MongoClientOptions } can be specified via the connection string . */
@ Override public Object getObjectInstance ( final Object obj , final Name name , final Context nameCtx , final Hashtable < ? , ? > environment ) throws Exception { } }

implementation:
// Some app servers , e . g . Wildfly , use the environment to pass location information to an ObjectFactory
String connectionString = null ; if ( environment . get ( CONNECTION_STRING ) instanceof String ) { connectionString = ( String ) environment . get ( CONNECTION_STRING ) ; } if ( connectionString == null || connectionString . isEmpty ( ) ) { LOGGER . debug ( format ( "No '%s' property in environment.  Casting 'obj' to java.naming.Reference to look for a " + "javax.naming.RefAddr with type equal to '%s'" , CONNECTION_STRING , CONNECTION_STRING ) ) ; // Some app servers , e . g . Tomcat , pass obj as an instance of javax . naming . Reference and pass location information in a
// javax . naming . RefAddr
if ( obj instanceof Reference ) { Enumeration < RefAddr > props = ( ( Reference ) obj ) . getAll ( ) ; while ( props . hasMoreElements ( ) ) { RefAddr addr = props . nextElement ( ) ; if ( addr != null ) { if ( CONNECTION_STRING . equals ( addr . getType ( ) ) ) { if ( addr . getContent ( ) instanceof String ) { connectionString = ( String ) addr . getContent ( ) ; break ; } } } } } } if ( connectionString == null || connectionString . isEmpty ( ) ) { throw new MongoException ( format ( "Could not locate '%s' in either environment or obj" , CONNECTION_STRING ) ) ; } MongoClientURI uri = new MongoClientURI ( connectionString ) ; return new MongoClient ( uri ) ;


signature:
public class DB { /** * Gets a collection with a given name .
 * @ param name the name of the collection to return
 * @ return the collection
 * @ throws IllegalArgumentException if the name is invalid
 * @ see MongoNamespace # checkCollectionNameValidity ( String ) */
public DBCollection getCollection ( final String name ) { } }

implementation: DBCollection collection = collectionCache . get ( name ) ; if ( collection != null ) { return collection ; } collection = new DBCollection ( name , this , executor ) ; if ( mongo . getMongoClientOptions ( ) . getDbDecoderFactory ( ) != DefaultDBDecoder . FACTORY ) { collection . setDBDecoderFactory ( mongo . getMongoClientOptions ( ) . getDbDecoderFactory ( ) ) ; } if ( mongo . getMongoClientOptions ( ) . getDbEncoderFactory ( ) != DefaultDBEncoder . FACTORY ) { collection . setDBEncoderFactory ( mongo . getMongoClientOptions ( ) . getDbEncoderFactory ( ) ) ; } DBCollection old = collectionCache . putIfAbsent ( name , collection ) ; return old != null ? old : collection ;


signature:
public class DB { /** * Drops this database . Removes all data on disk . Use with caution .
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / command / dropDatabase / Drop Database */
public void dropDatabase ( ) { } }

implementation: try { getExecutor ( ) . execute ( new DropDatabaseOperation ( getName ( ) , getWriteConcern ( ) ) , getReadConcern ( ) ) ; } catch ( MongoWriteConcernException e ) { throw createWriteConcernException ( e ) ; }


signature:
public class DB { /** * Returns a set containing the names of all collections in this database .
 * @ return the names of collections in this database
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / method / db . getCollectionNames / getCollectionNames ( ) */
public Set < String > getCollectionNames ( ) { } }

implementation: List < String > collectionNames = new MongoIterableImpl < DBObject > ( null , executor , ReadConcern . DEFAULT , primary ( ) , mongo . getMongoClientOptions ( ) . getRetryReads ( ) ) { @ Override public ReadOperation < BatchCursor < DBObject > > asReadOperation ( ) { return new ListCollectionsOperation < DBObject > ( name , commandCodec ) . nameOnly ( true ) ; } } . map ( new Function < DBObject , String > ( ) { @ Override public String apply ( final DBObject result ) { return ( String ) result . get ( "name" ) ; } } ) . into ( new ArrayList < String > ( ) ) ; Collections . sort ( collectionNames ) ; return new LinkedHashSet < String > ( collectionNames ) ;


signature:
public class DB { /** * < p > Creates a collection with a given name and options . If the collection already exists ,
 * this throws a { @ code CommandFailureException } . < / p >
 * < p > Possible options : < / p >
 * < ul >
 * < li > < b > capped < / b > ( { @ code boolean } ) - Enables a collection cap . False by default . If enabled ,
 * you must specify a size parameter . < / li >
 * < li > < b > size < / b > ( { @ code int } ) - If capped is true , size specifies a maximum size in bytes for the capped collection . When
 * capped is false , you may use size to preallocate space . < / li >
 * < li > < b > max < / b > ( { @ code int } ) - Optional . Specifies a maximum " cap " in number of documents for capped collections . You must
 * also specify size when specifying max . < / li >
 * < / ul >
 * < p > Note that if the { @ code options } parameter is { @ code null } , the creation will be deferred to when the collection is written
 * to . < / p >
 * @ param collectionName the name of the collection to return
 * @ param options options
 * @ return the collection
 * @ throws MongoCommandException if the server is unable to create the collection
 * @ throws WriteConcernException if the { @ code WriteConcern } specified on this { @ code DB } could not be satisfied
 * @ throws MongoException for all other failures
 * @ mongodb . driver . manual reference / method / db . createCollection / createCollection ( ) */
public DBCollection createCollection ( final String collectionName , @ Nullable final DBObject options ) { } }

implementation: if ( options != null ) { try { executor . execute ( getCreateCollectionOperation ( collectionName , options ) , getReadConcern ( ) ) ; } catch ( MongoWriteConcernException e ) { throw createWriteConcernException ( e ) ; } } return getCollection ( collectionName ) ;


signature:
public class DB { /** * Creates a view with the given name , backing collection / view name , and aggregation pipeline that defines the view .
 * @ param viewName the name of the view to create
 * @ param viewOn the backing collection / view for the view
 * @ param pipeline the pipeline that defines the view
 * @ return the view as a DBCollection
 * @ throws MongoCommandException if the server is unable to create the collection
 * @ throws WriteConcernException if the { @ code WriteConcern } specified on this { @ code DB } could not be satisfied
 * @ throws MongoException for all other failures
 * @ since 3.4
 * @ mongodb . server . release 3.4
 * @ mongodb . driver . manual reference / command / create Create Command */
public DBCollection createView ( final String viewName , final String viewOn , final List < ? extends DBObject > pipeline ) { } }

implementation: return createView ( viewName , viewOn , pipeline , new DBCreateViewOptions ( ) ) ;


signature:
public class DB { /** * Creates a view with the given name , backing collection / view name , aggregation pipeline , and options that defines the view .
 * @ param viewName the name of the view to create
 * @ param viewOn the backing collection / view for the view
 * @ param pipeline the pipeline that defines the view
 * @ param options the options for creating the view
 * @ return the view as a DBCollection
 * @ throws MongoCommandException if the server is unable to create the collection
 * @ throws WriteConcernException if the { @ code WriteConcern } specified on this { @ code DB } could not be satisfied
 * @ throws MongoException for all other failures
 * @ since 3.4
 * @ mongodb . server . release 3.4
 * @ mongodb . driver . manual reference / command / create Create Command */
public DBCollection createView ( final String viewName , final String viewOn , final List < ? extends DBObject > pipeline , final DBCreateViewOptions options ) { } }

implementation: try { notNull ( "options" , options ) ; DBCollection view = getCollection ( viewName ) ; executor . execute ( new CreateViewOperation ( name , viewName , viewOn , view . preparePipeline ( pipeline ) , writeConcern ) . collation ( options . getCollation ( ) ) , getReadConcern ( ) ) ; return view ; } catch ( MongoWriteConcernException e ) { throw createWriteConcernException ( e ) ; }


signature:
public class DB { /** * Executes a database command . This method constructs a simple DBObject using { @ code command } as the field name and { @ code true } as its
 * value , and calls { @ link DB # command ( DBObject , ReadPreference ) } with the default read preference for the database .
 * @ param command command to execute
 * @ return result of command from the database
 * @ throws MongoException if the command failed
 * @ mongodb . driver . manual tutorial / use - database - commands Commands */
public CommandResult command ( final String command ) { } }

implementation: return command ( new BasicDBObject ( command , Boolean . TRUE ) , getReadPreference ( ) ) ;


signature:
public class DB { /** * Executes a database command . This method calls { @ link DB # command ( DBObject , ReadPreference , DBEncoder ) } with the default read
 * preference for the database .
 * @ param command { @ code DBObject } representation of the command to be executed
 * @ param encoder { @ link DBEncoder } to be used for command encoding
 * @ return result of the command execution
 * @ throws MongoException if the command failed
 * @ mongodb . driver . manual tutorial / use - database - commands Commands */
public CommandResult command ( final DBObject command , final DBEncoder encoder ) { } }

implementation: return command ( command , getReadPreference ( ) , encoder ) ;


signature:
public class DB { /** * Executes a database command with the selected readPreference , and encodes the command using the given encoder .
 * @ param command The { @ code DBObject } representation the command to be executed
 * @ param readPreference Where to execute the command - this will only be applied for a subset of commands
 * @ param encoder The DBEncoder that knows how to serialise the command
 * @ return The result of executing the command , success or failure
 * @ mongodb . driver . manual tutorial / use - database - commands Commands
 * @ since 2.12 */
public CommandResult command ( final DBObject command , final ReadPreference readPreference , @ Nullable final DBEncoder encoder ) { } }

implementation: try { return executeCommand ( wrap ( command , encoder ) , getCommandReadPreference ( command , readPreference ) ) ; } catch ( MongoCommandException ex ) { return new CommandResult ( ex . getResponse ( ) , ex . getServerAddress ( ) ) ; }


signature:
public class DB { /** * Executes the command against the database with the given read preference .
 * @ param command The { @ code DBObject } representation the command to be executed
 * @ param readPreference Where to execute the command - this will only be applied for a subset of commands
 * @ return The result of executing the command , success or failure
 * @ mongodb . driver . manual tutorial / use - database - commands Commands
 * @ since 2.12 */
public CommandResult command ( final DBObject command , final ReadPreference readPreference ) { } }

implementation: return command ( command , readPreference , null ) ;


signature:
public class DB { /** * Executes a database command . This method constructs a simple { @ link DBObject } and calls { @ link DB # command ( DBObject , ReadPreference )
 * @ param command The name of the command to be executed
 * @ param readPreference Where to execute the command - this will only be applied for a subset of commands
 * @ return The result of the command execution
 * @ throws MongoException if the command failed
 * @ mongodb . driver . manual tutorial / use - database - commands Commands
 * @ since 2.12 */
public CommandResult command ( final String command , final ReadPreference readPreference ) { } }

implementation: return command ( new BasicDBObject ( command , true ) , readPreference ) ;


signature:
public class DB { /** * Checks to see if a collection with a given name exists on a server .
 * @ param collectionName a name of the collection to test for existence
 * @ return { @ code false } if no collection by that name exists , { @ code true } if a match to an existing collection was found
 * @ throws MongoException if the operation failed */
public boolean collectionExists ( final String collectionName ) { } }

implementation: Set < String > collectionNames = getCollectionNames ( ) ; for ( final String name : collectionNames ) { if ( name . equalsIgnoreCase ( collectionName ) ) { return true ; } } return false ;


signature:
public class DB { /** * Evaluates JavaScript functions on the database server . This is useful if you need to touch a lot of data lightly , in which case
 * network transfer could be a bottleneck .
 * @ param code { @ code String } representation of JavaScript function
 * @ param args arguments to pass to the JavaScript function
 * @ return result of the command execution
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / method / db . eval / db . eval ( )
 * @ deprecated The eval command was deprecated in MongoDB 3.0 */
@ Deprecated public CommandResult doEval ( final String code , final Object ... args ) { } }

implementation: DBObject commandDocument = new BasicDBObject ( "$eval" , code ) . append ( "args" , asList ( args ) ) ; return executeCommand ( wrap ( commandDocument ) ) ;


signature:
public class DB { /** * Calls { @ link DB # doEval ( java . lang . String , java . lang . Object [ ] ) } . If the command is successful , the " retval " field is extracted and
 * returned . Otherwise an exception is thrown .
 * @ param code { @ code String } representation of JavaScript function
 * @ param args arguments to pass to the JavaScript function
 * @ return result of the execution
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / method / db . eval / db . eval ( )
 * @ deprecated The eval command was deprecated in MongoDB 3.0 */
@ Deprecated public Object eval ( final String code , final Object ... args ) { } }

implementation: CommandResult result = doEval ( code , args ) ; result . throwOnError ( ) ; return result . get ( "retval" ) ;


signature:
public class DB { /** * Helper method for calling a ' dbStats ' command . It returns storage statistics for a given database .
 * @ return result of the execution
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / command / dbStats / Database Stats
 * @ deprecated Prefer { @ link # command ( DBObject ) } to run the dbStats command */
@ Deprecated public CommandResult getStats ( ) { } }

implementation: BsonDocument commandDocument = new BsonDocument ( "dbStats" , new BsonInt32 ( 1 ) ) . append ( "scale" , new BsonInt32 ( 1 ) ) ; return executeCommand ( commandDocument ) ;


signature:
public class DB { /** * Adds or updates a user for this database
 * < p > Never create or modify users over an insecure network without the use of TLS . < / p >
 * @ param userName the user name
 * @ param password the password
 * @ return the result of executing this operation
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual administration / security - access - control / Access Control
 * @ mongodb . driver . manual reference / command / createUser createUser
 * @ mongodb . driver . manual reference / command / updateUser updateUser
 * @ deprecated Use { @ code DB . command } to call either the createUser or updateUser command */
@ Deprecated public WriteResult addUser ( final String userName , final char [ ] password ) { } }

implementation: return addUser ( userName , password , false ) ;


signature:
public class DB { /** * Adds or updates a user for this database
 * < p > Never create or modify users over an insecure network without the use of TLS . < / p >
 * @ param userName the user name
 * @ param password the password
 * @ param readOnly if true , user will only be able to read
 * @ return the result of executing this operation
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual administration / security - access - control / Access Control
 * @ mongodb . driver . manual reference / command / createUser createUser
 * @ mongodb . driver . manual reference / command / updateUser updateUser
 * @ deprecated Use { @ code DB . command } to call either the createUser or updateUser command */
@ Deprecated public WriteResult addUser ( final String userName , final char [ ] password , final boolean readOnly ) { } }

implementation: MongoCredential credential = createCredential ( userName , getName ( ) , password ) ; boolean userExists = false ; try { userExists = executor . execute ( new com . mongodb . operation . UserExistsOperation ( getName ( ) , userName ) , primary ( ) , getReadConcern ( ) ) ; } catch ( MongoCommandException e ) { if ( e . getCode ( ) != 13 ) { throw e ; } } try { if ( userExists ) { executor . execute ( new com . mongodb . operation . UpdateUserOperation ( credential , readOnly , getWriteConcern ( ) ) , getReadConcern ( ) ) ; return new WriteResult ( 1 , true , null ) ; } else { executor . execute ( new com . mongodb . operation . CreateUserOperation ( credential , readOnly , getWriteConcern ( ) ) , getReadConcern ( ) ) ; return new WriteResult ( 1 , false , null ) ; } } catch ( MongoWriteConcernException e ) { throw createWriteConcernException ( e ) ; }


signature:
public class DB { /** * Removes the specified user from the database .
 * @ param userName user to be removed
 * @ return the result of executing this operation
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual administration / security - access - control / Access Control
 * @ deprecated Use { @ code DB . command } to call the dropUser command */
@ Deprecated public WriteResult removeUser ( final String userName ) { } }

implementation: try { executor . execute ( new com . mongodb . operation . DropUserOperation ( getName ( ) , userName , getWriteConcern ( ) ) , getReadConcern ( ) ) ; return new WriteResult ( 1 , true , null ) ; } catch ( MongoWriteConcernException e ) { throw createWriteConcernException ( e ) ; }


signature:
public class DB { /** * Determines the read preference that should be used for the given command .
 * @ param command the { @ link DBObject } representing the command
 * @ param requestedPreference the preference requested by the client .
 * @ return the read preference to use for the given command . It will never return { @ code null } .
 * @ see com . mongodb . ReadPreference */
ReadPreference getCommandReadPreference ( final DBObject command , @ Nullable final ReadPreference requestedPreference ) { } }

implementation: String comString = command . keySet ( ) . iterator ( ) . next ( ) . toLowerCase ( ) ; boolean primaryRequired = ! OBEDIENT_COMMANDS . contains ( comString ) ; if ( primaryRequired ) { return ReadPreference . primary ( ) ; } else if ( requestedPreference == null ) { return ReadPreference . primary ( ) ; } else { return requestedPreference ; }


signature:
public class GridFSTour { /** * Run this main method to see the output of this quick example .
 * @ param args takes an optional single argument for the connection string
 * @ throws FileNotFoundException if the sample file cannot be found
 * @ throws IOException if there was an exception closing an input stream */
public static void main ( final String [ ] args ) throws FileNotFoundException , IOException { } }

implementation:
MongoClient mongoClient ; if ( args . length == 0 ) { // connect to the local database server
mongoClient = MongoClients . create ( ) ; } else { mongoClient = MongoClients . create ( args [ 0 ] ) ; } // get handle to " mydb " database
MongoDatabase database = mongoClient . getDatabase ( "mydb" ) ; database . drop ( ) ; GridFSBucket gridFSBucket = GridFSBuckets . create ( database ) ; /* * UploadFromStream Example */
// Get the input stream
InputStream streamToUploadFrom = new ByteArrayInputStream ( "Hello World" . getBytes ( StandardCharsets . UTF_8 ) ) ; // Create some custom options
GridFSUploadOptions options = new GridFSUploadOptions ( ) . chunkSizeBytes ( 1024 ) . metadata ( new Document ( "type" , "presentation" ) ) ; ObjectId fileId = gridFSBucket . uploadFromStream ( "mongodb-tutorial" , streamToUploadFrom , options ) ; streamToUploadFrom . close ( ) ; System . out . println ( "The fileId of the uploaded file is: " + fileId . toHexString ( ) ) ; /* * OpenUploadStream Example */
// Get some data to write
byte [ ] data = "Data to upload into GridFS" . getBytes ( StandardCharsets . UTF_8 ) ; GridFSUploadStream uploadStream = gridFSBucket . openUploadStream ( "sampleData" ) ; uploadStream . write ( data ) ; uploadStream . close ( ) ; System . out . println ( "The fileId of the uploaded file is: " + uploadStream . getObjectId ( ) . toHexString ( ) ) ; /* * Find documents */
gridFSBucket . find ( ) . forEach ( new Block < GridFSFile > ( ) { @ Override public void apply ( final GridFSFile gridFSFile ) { System . out . println ( gridFSFile . getFilename ( ) ) ; } } ) ; /* * Find documents with a filter */
gridFSBucket . find ( eq ( "metadata.contentType" , "image/png" ) ) . forEach ( new Block < GridFSFile > ( ) { @ Override public void apply ( final GridFSFile gridFSFile ) { System . out . println ( gridFSFile . getFilename ( ) ) ; } } ) ; /* * DownloadToStream */
FileOutputStream streamToDownloadTo = new FileOutputStream ( "/tmp/mongodb-tutorial.txt" ) ; gridFSBucket . downloadToStream ( fileId , streamToDownloadTo ) ; streamToDownloadTo . close ( ) ; /* * DownloadToStreamByName */
streamToDownloadTo = new FileOutputStream ( "/tmp/mongodb-tutorial.txt" ) ; GridFSDownloadOptions downloadOptions = new GridFSDownloadOptions ( ) . revision ( 0 ) ; gridFSBucket . downloadToStream ( "mongodb-tutorial" , streamToDownloadTo , downloadOptions ) ; streamToDownloadTo . close ( ) ; /* * OpenDownloadStream */
GridFSDownloadStream downloadStream = gridFSBucket . openDownloadStream ( fileId ) ; int fileLength = ( int ) downloadStream . getGridFSFile ( ) . getLength ( ) ; byte [ ] bytesToWriteTo = new byte [ fileLength ] ; downloadStream . read ( bytesToWriteTo ) ; downloadStream . close ( ) ; System . out . println ( new String ( bytesToWriteTo , StandardCharsets . UTF_8 ) ) ; /* * OpenDownloadStreamByName */
downloadStream = gridFSBucket . openDownloadStream ( "sampleData" ) ; fileLength = ( int ) downloadStream . getGridFSFile ( ) . getLength ( ) ; bytesToWriteTo = new byte [ fileLength ] ; downloadStream . read ( bytesToWriteTo ) ; downloadStream . close ( ) ; System . out . println ( new String ( bytesToWriteTo , StandardCharsets . UTF_8 ) ) ; /* * Rename */
gridFSBucket . rename ( fileId , "mongodbTutorial" ) ; /* * Delete */
gridFSBucket . delete ( fileId ) ; database . drop ( ) ;


signature:
public class CodecRegistries { /** * A { @ code CodecRegistry } that combines the given { @ code CodecRegistry } instances into a single registry .
 * < p > The registries are checked in order until one returns a { @ code Codec } for the requested { @ code Class } . < / p >
 * < p > The created instance can handle cycles of { @ code Codec } dependencies , i . e when the construction of a { @ code Codec } for class A
 * requires the construction of a { @ code Codec } for class B , and vice versa . < / p >
 * < p > Any of the given registries that also implement { @ code CodecProvider } will be treated as a { @ code CodecProvider } instead of a
 * { @ code CodecRegistry } , which will ensure proper resolution of any dependencies between registries . < / p >
 * @ param registries the preferred registry for { @ code Codec } lookups
 * @ return a { @ code CodecRegistry } that combines the list of { @ code CodecRegistry } instances into a single one */
public static CodecRegistry fromRegistries ( final List < ? extends CodecRegistry > registries ) { } }

implementation: List < CodecProvider > providers = new ArrayList < CodecProvider > ( ) ; for ( CodecRegistry registry : registries ) { providers . add ( providerFromRegistry ( registry ) ) ; } return new ProvidersCodecRegistry ( providers ) ;


signature:
public class ChildCodecRegistry { /** * Gets a Codec , but if it detects a cyclic dependency , return a LazyCodec which breaks the chain . */
public < U > Codec < U > get ( final Class < U > clazz ) { } }

implementation: if ( hasCycles ( clazz ) ) { return new LazyCodec < U > ( registry , clazz ) ; } else { return registry . get ( new ChildCodecRegistry < U > ( this , clazz ) ) ; }


signature:
public class DBCollection { /** * Insert a document into a collection . If the collection does not exists on the server , then it will be created . If the new document
 * does not contain an ' _ id ' field , it will be added .
 * @ param document { @ code DBObject } to be inserted
 * @ param writeConcern { @ code WriteConcern } to be used during operation
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the insert command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / insert - documents / Insert Documents */
public WriteResult insert ( final DBObject document , final WriteConcern writeConcern ) { } }

implementation: return insert ( asList ( document ) , writeConcern ) ;


signature:
public class DBCollection { /** * Insert documents into a collection . If the collection does not exists on the server , then it will be created . If the new document
 * does not contain an ' _ id ' field , it will be added .
 * @ param documents { @ code DBObject } ' s to be inserted
 * @ param writeConcern { @ code WriteConcern } to be used during operation
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the insert command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / insert - documents / Insert Documents */
public WriteResult insert ( final DBObject [ ] documents , final WriteConcern writeConcern ) { } }

implementation: return insert ( asList ( documents ) , writeConcern ) ;


signature:
public class DBCollection { /** * Insert documents into a collection . If the collection does not exists on the server , then it will be created . If the new document
 * does not contain an ' _ id ' field , it will be added .
 * @ param documents list of { @ code DBObject } ' s to be inserted
 * @ param aWriteConcern { @ code WriteConcern } to be used during operation
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the insert command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / insert - documents / Insert Documents */
public WriteResult insert ( final List < ? extends DBObject > documents , final WriteConcern aWriteConcern ) { } }

implementation: return insert ( documents , aWriteConcern , null ) ;


signature:
public class DBCollection { /** * Insert documents into a collection . If the collection does not exists on the server , then it will be created . If the new document
 * does not contain an ' _ id ' field , it will be added .
 * @ param documents { @ code DBObject } ' s to be inserted
 * @ param aWriteConcern { @ code WriteConcern } to be used during operation
 * @ param encoder { @ code DBEncoder } to be used
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the insert command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / insert - documents / Insert Documents */
public WriteResult insert ( final DBObject [ ] documents , final WriteConcern aWriteConcern , final DBEncoder encoder ) { } }

implementation: return insert ( asList ( documents ) , aWriteConcern , encoder ) ;


signature:
public class DBCollection { /** * Insert documents into a collection . If the collection does not exists on the server , then it will be created . If the new document
 * does not contain an ' _ id ' field , it will be added .
 * @ param documents a list of { @ code DBObject } ' s to be inserted
 * @ param aWriteConcern { @ code WriteConcern } to be used during operation
 * @ param dbEncoder { @ code DBEncoder } to be used
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the insert command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / insert - documents / Insert Documents */
public WriteResult insert ( final List < ? extends DBObject > documents , final WriteConcern aWriteConcern , @ Nullable final DBEncoder dbEncoder ) { } }

implementation: return insert ( documents , new InsertOptions ( ) . writeConcern ( aWriteConcern ) . dbEncoder ( dbEncoder ) ) ;


signature:
public class DBCollection { /** * < p > Insert documents into a collection . If the collection does not exists on the server , then it will be created . If the new document
 * does not contain an ' _ id ' field , it will be added . < / p >
 * < p > If the value of the continueOnError property of the given { @ code InsertOptions } is true ,
 * that value will override the value of the continueOnError property of the given { @ code WriteConcern } . Otherwise ,
 * the value of the continueOnError property of the given { @ code WriteConcern } will take effect . < / p >
 * @ param documents a list of { @ code DBObject } ' s to be inserted
 * @ param insertOptions the options to use for the insert
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the insert command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / insert - documents / Insert Documents */
public WriteResult insert ( final List < ? extends DBObject > documents , final InsertOptions insertOptions ) { } }

implementation: WriteConcern writeConcern = insertOptions . getWriteConcern ( ) != null ? insertOptions . getWriteConcern ( ) : getWriteConcern ( ) ; Encoder < DBObject > encoder = toEncoder ( insertOptions . getDbEncoder ( ) ) ; List < InsertRequest > insertRequestList = new ArrayList < InsertRequest > ( documents . size ( ) ) ; for ( DBObject cur : documents ) { if ( cur . get ( ID_FIELD_NAME ) == null ) { cur . put ( ID_FIELD_NAME , new ObjectId ( ) ) ; } insertRequestList . add ( new InsertRequest ( new BsonDocumentWrapper < DBObject > ( cur , encoder ) ) ) ; } return insert ( insertRequestList , writeConcern , insertOptions . isContinueOnError ( ) , insertOptions . getBypassDocumentValidation ( ) ) ;


signature:
public class DBCollection { /** * Update an existing document or insert a document depending on the parameter . If the document does not contain an ' _ id ' field , then
 * the method performs an insert with the specified fields in the document as well as an ' _ id ' field with a unique objectId value . If
 * the document contains an ' _ id ' field , then the method performs an upsert querying the collection on the ' _ id ' field :
 * < ul >
 * < li > If a document does not exist with the specified ' _ id ' value , the method performs an insert with the specified fields in
 * the document . < / li >
 * < li > If a document exists with the specified ' _ id ' value , the method performs an update ,
 * replacing all field in the existing record with the fields from the document . < / li >
 * < / ul >
 * @ param document { @ link DBObject } to save to the collection .
 * @ param writeConcern { @ code WriteConcern } to be used during operation
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the insert or update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / # modify - a - document - with - save - method Save */
public WriteResult save ( final DBObject document , final WriteConcern writeConcern ) { } }

implementation: Object id = document . get ( ID_FIELD_NAME ) ; if ( id == null ) { return insert ( document , writeConcern ) ; } else { return replaceOrInsert ( document , id , writeConcern ) ; }


signature:
public class DBCollection { /** * Modify an existing document or documents in collection . The query parameter employs the same query selectors , as used in { @ code
 * find ( ) } .
 * @ param query the selection criteria for the update
 * @ param update the modifications to apply
 * @ param upsert when true , inserts a document if no document matches the update query criteria
 * @ param multi when true , updates all documents in the collection that match the update query criteria , otherwise only updates
 * one
 * @ param aWriteConcern { @ code WriteConcern } to be used during operation
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / Modify Documents */
public WriteResult update ( final DBObject query , final DBObject update , final boolean upsert , final boolean multi , final WriteConcern aWriteConcern ) { } }

implementation: return update ( query , update , upsert , multi , aWriteConcern , null ) ;


signature:
public class DBCollection { /** * Modify an existing document or documents in collection . By default the method updates a single document . The query parameter employs
 * the same query selectors , as used in { @ code find ( ) } .
 * @ param query the selection criteria for the update
 * @ param update the modifications to apply
 * @ param upsert when true , inserts a document if no document matches the update query criteria
 * @ param multi when true , updates all documents in the collection that match the update query criteria , otherwise only updates
 * one
 * @ param concern { @ code WriteConcern } to be used during operation
 * @ param encoder { @ code DBEncoder } to be used
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / Modify Documents */
public WriteResult update ( final DBObject query , final DBObject update , final boolean upsert , final boolean multi , final WriteConcern concern , @ Nullable final DBEncoder encoder ) { } }

implementation: return update ( query , update , upsert , multi , concern , null , encoder ) ;


signature:
public class DBCollection { /** * Modify an existing document or documents in collection . By default the method updates a single document . The query parameter employs
 * the same query selectors , as used in { @ link DBCollection # find ( DBObject ) } .
 * @ param query the selection criteria for the update
 * @ param update the modifications to apply
 * @ param upsert when true , inserts a document if no document matches the update query criteria
 * @ param multi when true , updates all documents in the collection that match the update query criteria , otherwise only updates one
 * @ param concern { @ code WriteConcern } to be used during operation
 * @ param bypassDocumentValidation whether to bypass document validation .
 * @ param encoder the DBEncoder to use
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / Modify
 * @ since 2.14 */
public WriteResult update ( final DBObject query , final DBObject update , final boolean upsert , final boolean multi , final WriteConcern concern , @ Nullable final Boolean bypassDocumentValidation , @ Nullable final DBEncoder encoder ) { } }

implementation: return update ( query , update , new DBCollectionUpdateOptions ( ) . upsert ( upsert ) . multi ( multi ) . writeConcern ( concern ) . bypassDocumentValidation ( bypassDocumentValidation ) . encoder ( encoder ) ) ;


signature:
public class DBCollection { /** * Modify an existing document or documents in collection . The query parameter employs the same query selectors , as used in { @ code
 * find ( ) } .
 * @ param query the selection criteria for the update
 * @ param update the modifications to apply
 * @ param upsert when true , inserts a document if no document matches the update query criteria
 * @ param multi when true , updates all documents in the collection that match the update query criteria , otherwise only updates one
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / Modify Documents */
public WriteResult update ( final DBObject query , final DBObject update , final boolean upsert , final boolean multi ) { } }

implementation: return update ( query , update , upsert , multi , getWriteConcern ( ) ) ;


signature:
public class DBCollection { /** * Modify an existing document . The query parameter employs the same query selectors , as used in { @ code find ( ) } .
 * @ param query the selection criteria for the update
 * @ param update the modifications to apply
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / Modify Documents */
public WriteResult update ( final DBObject query , final DBObject update ) { } }

implementation: return update ( query , update , false , false ) ;


signature:
public class DBCollection { /** * Modify documents in collection . The query parameter employs the same query selectors , as used in { @ code find ( ) } .
 * @ param query the selection criteria for the update
 * @ param update the modifications to apply
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / Modify Documents */
public WriteResult updateMulti ( final DBObject query , final DBObject update ) { } }

implementation: return update ( query , update , false , true ) ;


signature:
public class DBCollection { /** * Modify an existing document or documents in collection .
 * @ param query the selection criteria for the update
 * @ param update the modifications to apply
 * @ param options the options to apply to the update operation
 * @ return the result of the operation
 * @ throws com . mongodb . DuplicateKeyException if the write failed to a duplicate unique key
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the update command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / modify - documents / Modify
 * @ since 3.4 */
public WriteResult update ( final DBObject query , final DBObject update , final DBCollectionUpdateOptions options ) { } }

implementation: notNull ( "query" , query ) ; notNull ( "update" , update ) ; notNull ( "options" , options ) ; WriteConcern writeConcern = options . getWriteConcern ( ) != null ? options . getWriteConcern ( ) : getWriteConcern ( ) ; com . mongodb . bulk . WriteRequest . Type updateType = ! update . keySet ( ) . isEmpty ( ) && update . keySet ( ) . iterator ( ) . next ( ) . startsWith ( "$" ) ? com . mongodb . bulk . WriteRequest . Type . UPDATE : com . mongodb . bulk . WriteRequest . Type . REPLACE ; UpdateRequest updateRequest = new UpdateRequest ( wrap ( query ) , wrap ( update , options . getEncoder ( ) ) , updateType ) . upsert ( options . isUpsert ( ) ) . multi ( options . isMulti ( ) ) . collation ( options . getCollation ( ) ) . arrayFilters ( wrapAllowNull ( options . getArrayFilters ( ) , options . getEncoder ( ) ) ) ; return executeWriteOperation ( new UpdateOperation ( getNamespace ( ) , true , writeConcern , retryWrites , singletonList ( updateRequest ) ) . bypassDocumentValidation ( options . getBypassDocumentValidation ( ) ) ) ;


signature:
public class DBCollection { /** * Remove documents from a collection .
 * @ param query the deletion criteria using query operators . Omit the query parameter or pass an empty document to delete all
 * documents in the collection .
 * @ param writeConcern { @ code WriteConcern } to be used during operation
 * @ return the result of the operation
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the delete command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / remove - documents / Remove Documents */
public WriteResult remove ( final DBObject query , final WriteConcern writeConcern ) { } }

implementation: return remove ( query , new DBCollectionRemoveOptions ( ) . writeConcern ( writeConcern ) ) ;


signature:
public class DBCollection { /** * Remove documents from a collection .
 * @ param query the deletion criteria using query operators . Omit the query parameter or pass an empty document to delete all
 * documents in the collection .
 * @ param writeConcern { @ code WriteConcern } to be used during operation
 * @ param encoder { @ code DBEncoder } to be used
 * @ return the result of the operation
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the delete command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / remove - documents / Remove Documents */
public WriteResult remove ( final DBObject query , final WriteConcern writeConcern , final DBEncoder encoder ) { } }

implementation: return remove ( query , new DBCollectionRemoveOptions ( ) . writeConcern ( writeConcern ) . encoder ( encoder ) ) ;


signature:
public class DBCollection { /** * Remove documents from a collection .
 * @ param query the deletion criteria using query operators . Omit the query parameter or pass an empty document to delete all
 * documents in the collection .
 * @ param options the options to apply to the delete operation
 * @ return the result of the operation
 * @ throws com . mongodb . WriteConcernException if the write failed due some other failure specific to the delete command
 * @ throws MongoException if the operation failed for some other reason
 * @ mongodb . driver . manual tutorial / remove - documents / Remove Documents
 * @ since 3.4 */
public WriteResult remove ( final DBObject query , final DBCollectionRemoveOptions options ) { } }

implementation: notNull ( "query" , query ) ; notNull ( "options" , options ) ; WriteConcern writeConcern = options . getWriteConcern ( ) != null ? options . getWriteConcern ( ) : getWriteConcern ( ) ; DeleteRequest deleteRequest = new DeleteRequest ( wrap ( query , options . getEncoder ( ) ) ) . collation ( options . getCollation ( ) ) ; return executeWriteOperation ( new DeleteOperation ( getNamespace ( ) , false , writeConcern , retryWrites , singletonList ( deleteRequest ) ) ) ;


signature:
public class DBCollection { /** * Select documents in collection and get a cursor to the selected documents .
 * @ param query the selection criteria using query operators . Omit the query parameter or pass an empty document to return all
 * documents in the collection .
 * @ param projection specifies which fields MongoDB will return from the documents in the result set .
 * @ param numToSkip number of documents to skip
 * @ param batchSize see { @ link DBCursor # batchSize ( int ) } for more information
 * @ return A cursor to the documents that match the query criteria
 * @ mongodb . driver . manual tutorial / query - documents / Querying
 * @ deprecated use { @ link com . mongodb . DBCursor # skip ( int ) } and { @ link com . mongodb . DBCursor # batchSize ( int ) } on the { @ code DBCursor }
 * returned from { @ link com . mongodb . DBCollection # find ( DBObject , DBObject ) } */
@ Deprecated public DBCursor find ( final DBObject query , final DBObject projection , final int numToSkip , final int batchSize ) { } }

implementation: return new DBCursor ( this , query , projection , getReadPreference ( ) ) . batchSize ( batchSize ) . skip ( numToSkip ) ;


signature:
public class DBCollection { /** * Select documents in collection and get a cursor to the selected documents .
 * @ param query the selection criteria using query operators . Omit the query parameter or pass an empty document to return all
 * documents in the collection .
 * @ param projection specifies which fields MongoDB will return from the documents in the result set .
 * @ return A cursor to the documents that match the query criteria
 * @ mongodb . driver . manual tutorial / query - documents / Querying */
public DBCursor find ( final DBObject query , final DBObject projection ) { } }

implementation: return new DBCursor ( this , query , projection , getReadPreference ( ) ) ;


signature:
public class DBCollection { /** * Select documents in collection and get a cursor to the selected documents .
 * @ param query the selection criteria using query operators . Omit the query parameter or pass an empty document to return all
 * documents in the collection .
 * @ param options the options for the find operation .
 * @ return A cursor to the documents that match the query criteria
 * @ mongodb . driver . manual tutorial / query - documents / Querying
 * @ since 3.4 */
public DBCursor find ( @ Nullable final DBObject query , final DBCollectionFindOptions options ) { } }

implementation: return new DBCursor ( this , query , options ) ;


signature:
public class DBCollection { /** * Get a single document from collection .
 * @ param query the selection criteria using query operators .
 * @ return A document that satisfies the query specified as the argument to this method .
 * @ mongodb . driver . manual tutorial / query - documents / Querying */
@ Nullable public DBObject findOne ( final DBObject query ) { } }

implementation: return findOne ( query , null , null , getReadPreference ( ) ) ;


signature:
public class DBCollection { /** * Get a single document from collection .
 * @ param query the selection criteria using query operators .
 * @ param projection specifies which fields MongoDB will return from the documents in the result set .
 * @ return A document that satisfies the query specified as the argument to this method .
 * @ mongodb . driver . manual tutorial / query - documents / Querying */
@ Nullable public DBObject findOne ( final DBObject query , final DBObject projection ) { } }

implementation: return findOne ( query , projection , null , getReadPreference ( ) ) ;


signature:
public class DBCollection { /** * Get a single document from collection .
 * @ param query the selection criteria using query operators .
 * @ param projection specifies which fields MongoDB will return from the documents in the result set .
 * @ param sort A document whose fields specify the attributes on which to sort the result set .
 * @ return A document that satisfies the query specified as the argument to this method .
 * @ mongodb . driver . manual tutorial / query - documents / Querying */
@ Nullable public DBObject findOne ( final DBObject query , final DBObject projection , final DBObject sort ) { } }

implementation: return findOne ( query , projection , sort , getReadPreference ( ) ) ;


signature:
public class DBCollection { /** * Get a single document from collection .
 * @ param query the selection criteria using query operators .
 * @ param projection specifies which fields MongoDB will return from the documents in the result set .
 * @ param readPreference { @ link ReadPreference } to be used for this operation
 * @ return A document that satisfies the query specified as the argument to this method .
 * @ mongodb . driver . manual tutorial / query - documents / Querying */
@ Nullable public DBObject findOne ( final DBObject query , final DBObject projection , final ReadPreference readPreference ) { } }

implementation: return findOne ( query , projection , null , readPreference ) ;


signature:
public class DBCollection { /** * Get a single document from collection .
 * @ param query the selection criteria using query operators .
 * @ param projection specifies which projection MongoDB will return from the documents in the result set .
 * @ param sort A document whose fields specify the attributes on which to sort the result set .
 * @ param readPreference { @ code ReadPreference } to be used for this operation
 * @ return A document that satisfies the query specified as the argument to this method .
 * @ mongodb . driver . manual tutorial / query - documents / Querying */
@ Nullable public DBObject findOne ( @ Nullable final DBObject query , @ Nullable final DBObject projection , @ Nullable final DBObject sort , final ReadPreference readPreference ) { } }

implementation: return findOne ( query != null ? query : new BasicDBObject ( ) , new DBCollectionFindOptions ( ) . projection ( projection ) . sort ( sort ) . readPreference ( readPreference ) ) ;


signature:
public class DBCollection { /** * Get a single document from collection by ' _ id ' .
 * @ param id value of ' _ id ' field of a document we are looking for
 * @ param projection specifies which projection MongoDB will return from the documents in the result set .
 * @ return A document that satisfies the query specified as the argument to this method .
 * @ mongodb . driver . manual tutorial / query - documents / Querying */
@ Nullable public DBObject findOne ( final Object id , final DBObject projection ) { } }

implementation: return findOne ( new BasicDBObject ( "_id" , id ) , new DBCollectionFindOptions ( ) . projection ( projection ) ) ;


signature:
public class DBCollection { /** * Get a single document from collection .
 * @ param query the selection criteria using query operators .
 * @ param findOptions the options for the find operation .
 * @ return A document that satisfies the query specified as the argument to this method .
 * @ mongodb . driver . manual tutorial / query - documents / Querying
 * @ since 3.4 */
@ Nullable public DBObject findOne ( @ Nullable final DBObject query , final DBCollectionFindOptions findOptions ) { } }

implementation: return find ( query , findOptions ) . one ( ) ;


signature:
public class DBCollection { /** * Get the count of documents in collection that would match a criteria .
 * @ param query specifies the selection criteria
 * @ param readPreference { @ link ReadPreference } to be used for this operation
 * @ return the number of documents that matches selection criteria
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / command / count / Count */
public long count ( @ Nullable final DBObject query , final ReadPreference readPreference ) { } }

implementation: return getCount ( query , null , readPreference ) ;


signature:
public class DBCollection { /** * Get the count of documents in collection that would match a criteria .
 * @ param query specifies the selection criteria
 * @ param projection this is ignored
 * @ return the number of documents that matches selection criteria
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / command / count / Count
 * @ deprecated Prefer { @ link # count ( DBObject , DBCollectionCountOptions ) } */
@ Deprecated public long getCount ( @ Nullable final DBObject query , final DBObject projection ) { } }

implementation: return getCount ( query , projection , 0 , 0 ) ;


signature:
public class DBCollection { /** * Get the count of documents in collection that would match a criteria .
 * @ param query specifies the selection criteria
 * @ param projection this is ignored
 * @ param readPreference { @ link ReadPreference } to be used for this operation
 * @ return the number of documents that matches selection criteria
 * @ throws MongoException if the operation failed
 * @ mongodb . driver . manual reference / command / count / Count
 * @ deprecated Prefer { @ link # count ( DBObject , DBCollectionCountOptions ) } */
@ Deprecated public long getCount ( @ Nullable final DBObject query , @ Nullable final DBObject projection , final ReadPreference readPreference ) { } }

implementation: return getCount ( query , projection , 0 , 0 , readPreference ) ;