MongoDB

This is an enterprise feature.
<dependency>
	<groupId>one.microstream</groupId>
	<artifactId>microstream-enterprise-afs-mongodb</artifactId>
	<version>06.00.00-MS-GA</version>
</dependency>
MongoClient   mongoClient  = MongoClients.create();
MongoDatabase database     = mongoClient.getDatabase("db");
BlobStoreFileSystem fileSystem = BlobStoreFileSystem.New(
	MongoDbConnector.Caching(database)
);
EmbeddedStorage.start(fileSystem.ensureDirectoryPath("microstream_storage"));

Configuration

When using external configuration MongoDB can be set as follows.

microstream-storage.properties
storage-filesystem.mongodb.database=mydatabase
storage-filesystem.mongodb.auth-mechanism=mongo-cr
storage-filesystem.mongodb.username=username
storage-filesystem.mongodb.password=secret

Supported properties

Property Description

database

The database name for the storage target.

application-name

Sets the logical name of the application using this MongoClient. The application name may be used by the client to identify the application to the server, for use in server logs, slow query logs, and profile collection.

connection-string

Sets the connection string to connect to the service.

read-concern

The read concern level.

read-preference

The preferred replica set members to which a query or command can be sent.

write-concern

Controls the acknowledgment of write operations with various options.

  • w

    • 0: Don’t wait for acknowledgement from the server

    • 1: Wait for acknowledgement, but don’t wait for secondaries to replicate

    • >=2: Wait for one or more secondaries to also acknowledge

    • "majority": Wait for a majority of data bearing nodes to acknowledge

    • "<tag set name>": Wait for one or more secondaries to also acknowledge based on a tag set name

  • wtimeout - how long to wait for secondaries to acknowledge before failing

    • 0: indefinite

    • >0: time to wait in milliseconds

  • Other options:

    • journal: If true block until write operations have been committed to the journal. Cannot be used in combination with fsync. Write operations will fail with an exception if this option is used when the server is running without journaling.

retry-reads

Sets whether reads should be retried if they fail due to a network error.

retry-writes

Sets whether writes should be retried if they fail due to a network error.

uuid-representation

The representation to use when converting a UUID to a BSON binary value.This class is necessary because the different drivers used to have different ways of encoding UUID, with the BSON subtype: \x03 UUID old.

credentials.auth-mechanism

The type of the authentication mechanism. Supported values are:

  • "gssapi"
    Creates a MongoCredential instance for the GSSAPI SASL mechanism with the supplied "configuration.username" property. To override the default service name of "mongodb", add a mechanism property with the name "SERVICE_NAME". To force canonicalization of the host name prior to authentication, add a mechanism property with the name "CANONICALIZE_HOST_NAME" with the value true. To override the javax.security.auth.Subject with which the authentication executes, add a mechanism property with the name "JAVA_SUBJECT" with the value of a Subject instance. To override the properties of the javax.security.sasl.SaslClient with which the authentication executes, add a mechanism property with the name "JAVA_SASL_CLIENT_PROPERTIES" with the value of a Map<String, Object> instance containing the necessary properties. This can be useful if the application is customizing the default javax.security.sasl.SaslClientFactory.

  • "plain"
    Creates a MongoCredential instance for the PLAIN SASL mechanism. Credentials will be loaded from the credentials.username, credentials.source and credentials.password properties.

  • "mongodb-x509"
    Creates a MongoCredential instance for the MongoDB X.509 protocol with the supplied "configuration.username" property.

  • "mongo-cr"
    Creates a MongoCredential instance with an unspecified mechanism. The client will negotiate the best mechanism based on the version of the server that the client is authenticating to. Credentials will be loaded from the credentials.username and credentials.password properties.

credentials.username

The username, used for various auth mechanisms.

credentials.password

The password, used for various auth mechanisms.

credentials.source

The source where the user is defined. This can be either "$external" or the name of a database. Used when credentials.auth-mechanism=plain.

auth-mechanism-properties

Further properties for the authentication mechanism.