Class MongoDbMethods
- java.lang.Object
-
- io.toro.martini.MongoDbMethods
-
public final class MongoDbMethods extends Object
-
-
Constructor Summary
Constructors Constructor Description MongoDbMethods(io.toro.martini.database.DataSourceManager manager)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
abortTransaction(@NotNull ClientSession clientSession)
Abort a transaction in the context of this session.static GloopCursor
aggregate(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, List<? extends org.bson.conversions.Bson> pipeline, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Aggregates documents according to the specified aggregation pipeline.static GloopCursor
aggregateWithQuery(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, @NotNull List<String> pipelineQueries, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Aggregates documents according to the specified aggregation pipeline.static GloopCursor
bulkWrite(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, int batchSize, boolean closeClient, boolean ordered, Boolean bypassDocumentValidation, GloopExecutionContext context)
Executes a mix of inserts, updates, replaces, and deletes.static void
commitTransaction(@NotNull ClientSession clientSession)
Commit a transaction in the context of this session.static io.toro.martini.database.MongoDbDataSource
connection(String connectionName)
Return mongo datasource objectString
connectionToString(@NotNull String connectionName)
Returns a string representation of the mongo client object.static long
countDocuments(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter)
Counts the number of documents in the collection according to the given options.static long
countDocuments(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, String query, ClientSession clientSession)
Counts the number of documents in the collection according to the given options.static void
createDatabaseAndCollection(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession)
Create a new collection with the given name.static String
createIndex(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull String keys, IndexOptions indexOptions)
Create an index with the given keys and options.static String
createIndex(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull org.bson.conversions.Bson keys, IndexOptions indexOptions)
Create an index with the given keys and options.static List<String>
createIndexes(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions)
Create multiple indexes.static void
createView(@NotNull String connectionName, @NotNull String databaseName, @NotNull String viewName, String viewOn, List<? extends org.bson.conversions.Bson> pipeline, ClientSession clientSession, @NotNull CreateViewOptions createViewOptions)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.static DeleteResult
deleteMany(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, String filterQuery, DeleteOptions options)
Removes all documents from the collection that match the given query filter.static DeleteResult
deleteMany(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, DeleteOptions options)
Removes all documents from the collection that match the given query filter.static DeleteResult
deleteOne(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, String filterQuery, DeleteOptions options)
Removes at most one document from the collection that matches the given filter.static DeleteResult
deleteOne(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, DeleteOptions options)
Removes at most one document from the collection that matches the given filter.static <T> GloopCursor
distinct(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, @NotNull String fieldName, @NotNull String query, ClientSession clientSession, Class<T> resultClass, boolean closeClient, GloopExecutionContext context)
Gets the distinct values of the specified field name.static <T> GloopCursor
distinct(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, @NotNull String fieldName, org.bson.conversions.Bson filter, ClientSession clientSession, @NotNull Class<T> resultClass, boolean closeClient, GloopExecutionContext context)
Gets the distinct values of the specified field name.static void
drop(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession)
Drops this collection from the Database.static void
drop(@NotNull String connectionName, @NotNull String databaseName, ClientSession clientSession)
Drops this database.static void
dropCollection(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession)
Drop a collection with the given name.static void
dropDatabase(@NotNull String connectionName, @NotNull String databaseName)
Drops the database if it exists.static void
dropIndex(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull String indexName, DropIndexOptions dropIndexOptions)
Drops the index given its name.static void
dropIndexes(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, DropIndexOptions dropIndexOptions)
Drop all the indexes on this collection, except for the default on _id.static long
estimatedDocumentCount(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, @javax.validation.constraints.NotNull long maxTime)
Gets an estimate of the count of documents in a collection using collection metadata.static GloopModel
find(@NotNull MongoClient client, @NotNull String databaseName, @NotNull String collection, String filter, String projection, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Open a Mongo Input cursor that will use the Gloop codec to convert records in MongoDB to Gloop Modelsstatic GloopModel
find(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collection, String filter, String projection, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Open a Mongo Input cursor that will use the Gloop codec to convert records in MongoDB to Gloop Modelsstatic GloopModel
findFirst(@NotNull MongoClient client, @NotNull String databaseName, @NotNull String collection, String filter, String projection, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Return a gloop model, which is the first result of the given querystatic GloopModel
findFirst(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collection, String filter, String projection, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Return a gloop model, which is the first result of the given querystatic GloopModel
findOneAndDelete(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull String filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.static GloopModel
findOneAndDelete(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull org.bson.conversions.Bson filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.static GloopModel
findOneAndReplace(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, String filter, GloopModel replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.static GloopModel
findOneAndReplace(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, GloopModel replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.static GloopModel
findOneAndUpdate(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull String filter, @NotNull String update, FindOneAndUpdateOptions options)
Atomically find a document and update it.static GloopModel
findOneAndUpdate(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull org.bson.conversions.Bson filter, @NotNull org.bson.conversions.Bson update, FindOneAndUpdateOptions options)
Atomically find a document and update it.static org.bson.Document
fsync(@NotNull String connectionName, boolean async)
Forces the master server to fsync the RAM data to disk.static org.bson.Document
fsyncAndLock(@NotNull String connectionName)
Forces the master server to fsync the RAM data to disk, then lock all writes.static String
getConnectPoint(@NotNull String connectionName)
Gets aString
representation of current connection point, i.e.static org.bson.Document
getCredentialsList(@NotNull String connectionName)
Gets the list of credentials that this client authenticates all connections withMongoDatabase
getDatabase(@NotNull String connectionName, @NotNull String databaseName)
static org.bson.codecs.configuration.CodecRegistry
getDefaultCodecRegistry()
Gets the default codec registry.static org.bson.codecs.configuration.CodecRegistry
getGloopCodecRegistry()
Returns a codec registry which contains the Codec for Gloop Models.static org.bson.Document
getMongoClientOptions(@NotNull String connectionName)
Gets the options that this client uses to connect to server.static TransactionOptions
getTransactionOptions(@NotNull ClientSession clientSession)
Gets the transaction options.static org.bson.Document
getUsedDatabases(@NotNull String connectionName)
Returns the list of databases used by the driver since this Mongo instance was created.static boolean
hasActiveTransaction(@NotNull ClientSession clientSession)
Returns true if there is an active transaction on this session, and false otherwisestatic GloopCursor
insertMany(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collection, int batchSize, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Open a Mongo Output cursor that will use the Gloop Codec to convert Gloop Models to Mongo DB documents, allowing Gloop to write records.static void
insertMany(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull List<GloopModel> documents, boolean ordered, Boolean bypassDocumentValidation)
Inserts one or more documents.static void
insertOne(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull GloopModel document, Boolean bypassDocumentValidation)
Inserts the provided document.static boolean
isLocked(@NotNull String connectionName)
Returns true if the database is locked (read-only), false otherwise.static List<String>
listCollectionNames(@NotNull String connectionName, @NotNull String databaseName, ClientSession clientSession)
Gets the names of all the collections in this database.static GloopModel
listCollections(@NotNull String connectionName, @NotNull String databaseName, ClientSession clientSession)
Finds all the collections in this database.static Collection<String>
listDatabaseNames(@NotNull String connectionName, ClientSession clientSession)
Get a list of the database namesstatic GloopModel
listDatabases(@NotNull String connectionName, ClientSession clientSession)
Gets the list of databasesstatic GloopCursor
listIndexes(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, boolean closeClient, GloopExecutionContext context)
Get all the indexes in this collection.static <T> GloopCursor
mapReduce(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, Class<T> resultClass, @NotNull String mapFunction, @NotNull String reduceFunction, boolean closeClient, GloopExecutionContext context)
Aggregates documents according to the specified map-reduce function.static void
renameCollection(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, MongoNamespace newCollectionNamespace, boolean dropTarget)
Rename the collection with oldCollectionName to the newCollectionName.static UpdateResult
replaceOne(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, String filterQuery, GloopModel replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.static UpdateResult
replaceOne(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, GloopModel replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.static GloopModel
runCommand(@NotNull String connectionName, @NotNull String databaseName, ClientSession clientSession, @NotNull String query)
Executes the given command in the context of the current database with a read preference ofReadPreference.primary()
.static GloopModel
runCommand(@NotNull String connectionName, @NotNull String databaseName, ClientSession clientSession, @NotNull org.bson.conversions.Bson command)
Executes the given command in the context of the current database with a read preference ofReadPreference.primary()
.(package private) static void
setDataSourceManager(io.toro.martini.database.DataSourceManager manager)
static ClientSession
startSession(@NotNull String connectionName, ClientSessionOptions options)
Creates a client session.static ClientSession
startSession(@NotNull String connectionName, GloopModel clientSessionOptions)
Creates a client session.static void
startTransaction(@NotNull ClientSession clientSession, TransactionOptions transactionOptions)
Start a transaction in the context of this session with the given transaction options.static void
startTransaction(@NotNull ClientSession clientSession, GloopModel transactionOptions)
Start a transaction in the context of this session with the given transaction options.static org.bson.Document
unlock(@NotNull String connectionName)
Unlocks the database, allowing the write operations to go through.static UpdateResult
updateMany(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, String filter, String update, UpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.static UpdateResult
updateMany(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, org.bson.conversions.Bson update, UpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.static UpdateResult
updateOne(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull String filter, @NotNull String update, UpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.static UpdateResult
updateOne(@NotNull String connectionName, @NotNull String databaseName, @NotNull String collectionName, ClientSession clientSession, @NotNull org.bson.conversions.Bson filter, @NotNull org.bson.conversions.Bson update, UpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.static void
watch(@NotNull String connectionName, @NotNull String databaseName, ClientSession clientSession, List<? extends org.bson.conversions.Bson> pipeline, @NotNull String gloopService)
Creates a change stream for this database.static ChangeStreamIterable<org.bson.Document>
watch(@NotNull String connectionName, ClientSession clientSession, List<? extends org.bson.conversions.Bson> pipeline)
Creates a change stream for this client.static ChangeStreamIterable<org.bson.Document>
watchWithQuery(@NotNull String connectionName, ClientSession clientSession, List<String> pipelineQueries)
Creates a change stream for this client.
-
-
-
Constructor Detail
-
MongoDbMethods
@Autowired MongoDbMethods(io.toro.martini.database.DataSourceManager manager)
-
-
Method Detail
-
setDataSourceManager
static void setDataSourceManager(io.toro.martini.database.DataSourceManager manager)
-
getGloopCodecRegistry
public static org.bson.codecs.configuration.CodecRegistry getGloopCodecRegistry()
Returns a codec registry which contains the Codec for Gloop Models. If you're creating your own Mongo Client for use with Gloop, this registry must be added. Example:import static org.bson.codecs.configuration.CodecRegistries.fromProviders; import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; ... CodecRegistry pojoCodecRegistry = fromRegistries( MongoClient.getDefaultCodecRegistry(), MongoDbMethods.getGloopCodecRegistry(), // <-- added gloop codec here fromProviders( PojoCodecProvider.builder().automatic( true ).build() ) ); return new MongoClient( host, MongoClientOptions.builder().codecRegistry( pojoCodecRegistry ).build() );
- Since:
- 1.0
-
find
@GloopObjectParameter("output{\n mongoFindCursor[]*{\n }\n}") public static GloopModel find(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collection, String filter, String projection, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Open a Mongo Input cursor that will use the Gloop codec to convert records in MongoDB to Gloop Models- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the databaseName namecollection
- the collection namefilter
- selection filter using query operators.projection
- specifies the fields to return in the documents that match the query filterclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhaustedcontext
- the Gloop Execution Context- Since:
- 1.0
-
find
@GloopObjectParameter("output{\n mongoFindCursor[]*{\n }\n}") public static GloopModel find(@NotNull @NotNull MongoClient client, @NotNull @NotNull String databaseName, @NotNull @NotNull String collection, String filter, String projection, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Open a Mongo Input cursor that will use the Gloop codec to convert records in MongoDB to Gloop Models- Parameters:
client
- a pre-configured Mongo client, which must have the GloopCodec included. Seehere
.databaseName
- the databaseName namecollection
- the collection namefilter
- selection filter using query operators.projection
- specifies the fields to return in the documents that match the query filterclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhaustedcontext
- the Gloop Execution Context- Since:
- 1.0
-
findFirst
@GloopObjectParameter("output{\n mongoResult*{\n }\n}") public static GloopModel findFirst(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collection, String filter, String projection, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Return a gloop model, which is the first result of the given query- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the databaseName namecollection
- the collection namefilter
- selection filter using query operators.projection
- specifies the fields to return in the documents that match the query filterclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhaustedcontext
- the Gloop Execution Context- Returns:
- GloopModel the first item or null.
- Since:
- 1.0
-
findFirst
@GloopObjectParameter("output{\n mongoResult*{\n }\n}") public static GloopModel findFirst(@NotNull @NotNull MongoClient client, @NotNull @NotNull String databaseName, @NotNull @NotNull String collection, String filter, String projection, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Return a gloop model, which is the first result of the given query- Parameters:
client
- a pre-configured Mongo client, which must have the GloopCodec included. Seehere
.databaseName
- the databaseName namecollection
- the collection namefilter
- selection filter using query operators.projection
- specifies the fields to return in the documents that match the query filterclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhaustedcontext
- the Gloop Execution Context- Returns:
- GloopModel the first item or null.
- Since:
- 1.0
-
insertMany
@GloopObjectParameter("mongoInsertCursor{\n mongoInsertCursor[]*{\n }\n}") public static GloopCursor insertMany(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collection, @GloopParameter(defaultValue="10000") int batchSize, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Open a Mongo Output cursor that will use the Gloop Codec to convert Gloop Models to Mongo DB documents, allowing Gloop to write records.- Parameters:
connectionName
- the name of the connectiondatabaseName
- the databaseName namecollection
- the collection nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhaustedcontext
- the Gloop Execution Context- Since:
- 1.0
-
insertMany
public static void insertMany(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull List<GloopModel> documents, @GloopParameter(defaultValue="false") boolean ordered, Boolean bypassDocumentValidation)
Inserts one or more documents. A call to this method is equivalent to a call to thebulkWrite
methodNote: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessiondocuments
- the documents to insert- Throws:
DuplicateKeyException
- if the write failed to a duplicate unique keyWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
getUsedDatabases
public static org.bson.Document getUsedDatabases(@NotNull @NotNull String connectionName)
Returns the list of databases used by the driver since this Mongo instance was created. This may include DBs that exist in the client but not yet on the server.- Parameters:
connectionName
- the name of the mongo db connection- Returns:
- a collection of database objects
- Since:
- 1.0
-
dropDatabase
public static void dropDatabase(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName)
Drops the database if it exists.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- name of database to drop- Throws:
MongoException
- if the operation fails- Since:
- 1.0
-
fsync
public static org.bson.Document fsync(@NotNull @NotNull String connectionName, @GloopParameter(defaultValue="false") boolean async)
Forces the master server to fsync the RAM data to disk. This is done automatically by the server at intervals, but can be forced for better reliability.- Parameters:
connectionName
- the name of the mongo db connectionasync
- if true, the fsync will be done asynchronously on the server.- Returns:
- result of the command execution
- Throws:
MongoException
- if there's a failure- Since:
- 1.0
-
fsyncAndLock
public static org.bson.Document fsyncAndLock(@NotNull @NotNull String connectionName)
Forces the master server to fsync the RAM data to disk, then lock all writes. The database will be read-only after this command returns.- Parameters:
connectionName
- the name of the mongo db connection- Returns:
- result of the command execution
- Throws:
MongoException
- if there's a failure- Since:
- 1.0
-
unlock
public static org.bson.Document unlock(@NotNull @NotNull String connectionName)
Unlocks the database, allowing the write operations to go through. This command may be asynchronous on the server, which means there may be a small delay before the database becomes writable.- Parameters:
connectionName
- the name of the mongo db connection- Returns:
DBObject
in the following form{"ok": 1,"info": "unlock completed"}
- Throws:
MongoException
- if there's a failure- Since:
- 1.0
-
isLocked
public static boolean isLocked(@NotNull @NotNull String connectionName)
Returns true if the database is locked (read-only), false otherwise.- Parameters:
connectionName
- the name of the mongo db connection- Returns:
- result of the command execution
- Throws:
MongoException
- if the operation fails- Since:
- 1.0
-
connectionToString
public String connectionToString(@NotNull @NotNull String connectionName)
Returns a string representation of the mongo client object.- Parameters:
connectionName
- the name of the mongo db connection- Returns:
- result of the command execution
- Throws:
MongoException
- if the operation fails- Since:
- 1.0
-
connection
public static io.toro.martini.database.MongoDbDataSource connection(String connectionName)
Return mongo datasource object- Parameters:
connectionName
- the name of the saved database connection in Martini- Returns:
- datasource
-
getConnectPoint
@Nullable public static String getConnectPoint(@NotNull @NotNull String connectionName)
Gets aString
representation of current connection point, i.e. master.- Parameters:
connectionName
- the name of the mongo db connection- Returns:
- server address in a host:port form
- Since:
- 1.0
-
getDefaultCodecRegistry
public static org.bson.codecs.configuration.CodecRegistry getDefaultCodecRegistry()
Gets the default codec registry. It includes the following providers:ValueCodecProvider
BsonValueCodecProvider
DBRefCodecProvider
DBObjectCodecProvider
DocumentCodecProvider
IterableCodecProvider
MapCodecProvider
GeoJsonCodecProvider
GridFSFileCodecProvider
Jsr310CodecProvider
- Returns:
- the default codec registry
- Since:
- 1.0
- See Also:
MongoClientSettings.getDefaultCodecRegistry()
-
getMongoClientOptions
public static org.bson.Document getMongoClientOptions(@NotNull @NotNull String connectionName)
Gets the options that this client uses to connect to server.- Parameters:
connectionName
- the name of the mongo db connection- Returns:
- the options
- Since:
- 1.0
-
getCredentialsList
public static org.bson.Document getCredentialsList(@NotNull @NotNull String connectionName)
Gets the list of credentials that this client authenticates all connections with- Parameters:
connectionName
- the name of the mongo db connection- Returns:
- the list of credentials
- Since:
- 1.0
-
startSession
public static ClientSession startSession(@NotNull @NotNull String connectionName, ClientSessionOptions options)
Creates a client session.Note: A ClientSession instance can not be used concurrently in multiple operations.
- Parameters:
connectionName
- the name of the mongo db connectionoptions
- the options for the client session. If null, default options will be used- Returns:
- the client session
- Since:
- 1.0
-
startSession
@GloopParameter(name="$clientSession") public static ClientSession startSession(@NotNull @NotNull String connectionName, @GloopObjectParameter("clientSessionOptions#io.toro.martini.mongodb.ClientSessionOptions{\n}\n") GloopModel clientSessionOptions)
Creates a client session.Note: A ClientSession instance can not be used concurrently in multiple operations.
- Parameters:
connectionName
- the name of the mongo db connectionclientSessionOptions
- the options for the client session. If null, default options will be used- Returns:
- the client session
- Since:
- 1.0
-
startTransaction
public static void startTransaction(@NotNull @NotNull ClientSession clientSession, TransactionOptions transactionOptions)
Start a transaction in the context of this session with the given transaction options. A transaction can not be started if there is already an active transaction on this session.- Parameters:
clientSession
- the client sessiontransactionOptions
- the options to apply to the transaction- Since:
- 1.0
-
startTransaction
public static void startTransaction(@NotNull @NotNull ClientSession clientSession, @GloopObjectParameter("transactionOptions#io.toro.martini.mongodb.TransactionOptions{\n}\n") GloopModel transactionOptions)
Start a transaction in the context of this session with the given transaction options. A transaction can not be started if there is already an active transaction on this session.- Parameters:
clientSession
- the client sessiontransactionOptions
- the options to apply to the transaction- Since:
- 1.0
-
hasActiveTransaction
public static boolean hasActiveTransaction(@NotNull @NotNull ClientSession clientSession)
Returns true if there is an active transaction on this session, and false otherwise- Parameters:
clientSession
- the client session- Returns:
- true if there is an active transaction on this session
- Since:
- 1.0
-
getTransactionOptions
public static TransactionOptions getTransactionOptions(@NotNull @NotNull ClientSession clientSession)
Gets the transaction options. Only call this method of the session has an active transaction- Parameters:
clientSession
- the client session*- Returns:
- the transaction options
- Since:
- 1.0
-
commitTransaction
public static void commitTransaction(@NotNull @NotNull ClientSession clientSession)
Commit a transaction in the context of this session. A transaction can only be committed if one has first been started.- Parameters:
clientSession
- the client session*- Since:
- 1.0
-
abortTransaction
public static void abortTransaction(@NotNull @NotNull ClientSession clientSession)
Abort a transaction in the context of this session. A transaction can only be aborted if one has first been started.- Parameters:
clientSession
- the client session- Since:
- 1.0
-
listDatabaseNames
public static Collection<String> listDatabaseNames(@NotNull @NotNull String connectionName, ClientSession clientSession)
Get a list of the database names- Parameters:
connectionName
- the name of the mongo db connectionclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Returns:
- an iterable containing all the names of all the databases
- Since:
- 1.0
-
listDatabases
@GloopObjectParameter("output{\n mongoDbDatabases#io.toro.martini.mongodb.Database[]{\n }\n}") public static GloopModel listDatabases(@NotNull @NotNull String connectionName, ClientSession clientSession)
Gets the list of databases- Parameters:
connectionName
- the name of the mongo db connectionclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Returns:
- the list databases iterable interface
- Since:
- 1.0
-
getDatabase
public MongoDatabase getDatabase(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName)
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the name of the database to retrieve- Returns:
- a
MongoDatabase
representing the specified database - Throws:
IllegalArgumentException
- if databaseName is invalid- Since:
- 1.0
- See Also:
MongoNamespace.checkDatabaseNameValidity(String)
-
runCommand
public static GloopModel runCommand(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, ClientSession clientSession, @NotNull @NotNull org.bson.conversions.Bson command)
Executes the given command in the context of the current database with a read preference ofReadPreference.primary()
.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncommand
- the command to be run- Returns:
- the command result
- Since:
- 1.0
-
runCommand
public static GloopModel runCommand(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, ClientSession clientSession, @NotNull @NotNull String query)
Executes the given command in the context of the current database with a read preference ofReadPreference.primary()
.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionquery
- the command to be run- Returns:
- the command result
- Since:
- 1.0
-
drop
public static void drop(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, ClientSession clientSession)
Drops this database.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Since:
- 1.0
-
drop
public static void drop(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession)
Drops this collection from the Database.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Since:
- 1.0
-
listCollectionNames
public static List<String> listCollectionNames(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, ClientSession clientSession)
Gets the names of all the collections in this database.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Returns:
- an iterable containing all the names of all the collections in this database
- Since:
- 1.0
-
listCollections
@GloopObjectParameter("output{\n mongoDbCollections#io.toro.martini.mongodb.Collection[]{\n }\n}") public static GloopModel listCollections(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, ClientSession clientSession)
Finds all the collections in this database.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Returns:
- the list collections iterable interface
- Since:
- 1.0
-
createDatabaseAndCollection
public static void createDatabaseAndCollection(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession)
Create a new collection with the given name.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database name, will be created if it doesn't already existcollectionName
- the name for the new collection to createclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Since:
- 1.0
-
dropCollection
public static void dropCollection(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession)
Drop a collection with the given name.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the name for the collection to dropclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Since:
- 1.0
-
createView
public static void createView(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String viewName, String viewOn, List<? extends org.bson.conversions.Bson> pipeline, ClientSession clientSession, @NotNull @NotNull CreateViewOptions createViewOptions)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameviewName
- the name of the view to createviewOn
- the backing collection/view for the viewpipeline
- the pipeline that defines the viewclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncreateViewOptions
- create view options- Since:
- 1.0
-
countDocuments
public static long countDocuments(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter)
Counts the number of documents in the collection according to the given options.Note: When migrating from
count()
tocountDocuments()
the following query operators must be replaced:+-------------+--------------------------------+ | Operator | Replacement | +=============+================================+ | $where | $expr | +-------------+--------------------------------+ | $near | $geoWithin with $center | +-------------+--------------------------------+ | $nearSphere | $geoWithin with $centerSphere | +-------------+--------------------------------+
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the collection nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter- Returns:
- the number of documents in the collection
- Since:
- 1.0
-
countDocuments
public static long countDocuments(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, String query, ClientSession clientSession)
Counts the number of documents in the collection according to the given options.- Parameters:
query
- leave null to count all documents in the collectionNote: When migrating from
count()
tocountDocuments()
the following query operators must be replaced:+-------------+--------------------------------+ | Operator | Replacement | +=============+================================+ | $where | $expr | +-------------+--------------------------------+ | $near | $geoWithin with $center | +-------------+--------------------------------+ | $nearSphere | $geoWithin with $centerSphere | +-------------+--------------------------------+
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the collection nameclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Returns:
- the number of documents in the collection
- Since:
- 1.0
-
estimatedDocumentCount
public static long estimatedDocumentCount(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, @NotNull @javax.validation.constraints.NotNull long maxTime)
Gets an estimate of the count of documents in a collection using collection metadata.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the collection namemaxTime
- The maximum time to wait in milliseconds. Set to a number <= 0 for no time limit.- Returns:
- the number of documents in the collection
- Since:
- 1.0
-
distinct
@GloopObjectParameter("mongoDbDistinctValuesCursor[]:object") public static <T> GloopCursor distinct(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, @NotNull @NotNull String fieldName, org.bson.conversions.Bson filter, ClientSession clientSession, @NotNull @NotNull Class<T> resultClass, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Gets the distinct values of the specified field name.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the collection namefieldName
- the field nameresultClass
- the class to cast any distinct items into.filter
- the filterclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhausted- Returns:
- an iterable of distinct values
- Since:
- 1.0
-
distinct
@GloopObjectParameter("distinctValuesCursor[]:object") public static <T> GloopCursor distinct(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, @NotNull @NotNull String fieldName, @NotNull @NotNull String query, ClientSession clientSession, Class<T> resultClass, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Gets the distinct values of the specified field name.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the collection namefieldName
- the field namequery
- the queryclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionresultClass
- the class to cast any distinct items into.closeClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhausted- Returns:
- an iterable of distinct values
- Since:
- 1.0
-
aggregate
@GloopObjectParameter("mongoAggregateCursor[]:object") public static GloopCursor aggregate(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, List<? extends org.bson.conversions.Bson> pipeline, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Aggregates documents according to the specified aggregation pipeline.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the collection namepipeline
- the aggregation pipelineclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhausted- Returns:
- an iterable containing the result of the aggregation operation
- Since:
- 1.0
-
aggregateWithQuery
@GloopObjectParameter("mongoAggregateCursor[]:object") public static GloopCursor aggregateWithQuery(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, @NotNull @NotNull List<String> pipelineQueries, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Aggregates documents according to the specified aggregation pipeline.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database namecollectionName
- the collection namepipelineQueries
- the aggregation pipeline queriesclientSession
- the client session with which to associate this operation. Leave as null if there is no sessioncloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhausted- Returns:
- an iterable containing the result of the aggregation operation
- Since:
- 1.0
-
watch
public static ChangeStreamIterable<org.bson.Document> watch(@NotNull @NotNull String connectionName, ClientSession clientSession, List<? extends org.bson.conversions.Bson> pipeline)
Creates a change stream for this client.- Parameters:
connectionName
- the name of the mongo db connectionclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionpipeline
- the aggregation pipeline to apply to the change stream. Leave as null if there are no queries- Returns:
- the change stream iterable
- Since:
- 1.0
-
watch
@GloopObjectParameter("output{\n mongoAggregateCursor[]*{\n }\n}") public static void watch(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, ClientSession clientSession, List<? extends org.bson.conversions.Bson> pipeline, @NotNull @NotNull String gloopService)
Creates a change stream for this database.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionpipeline
- the aggregation pipeline to apply to the change streamgloopService
- The gloop service to invoke when a change is made- Since:
- 1.0
-
watchWithQuery
public static ChangeStreamIterable<org.bson.Document> watchWithQuery(@NotNull @NotNull String connectionName, ClientSession clientSession, List<String> pipelineQueries)
Creates a change stream for this client.- Parameters:
connectionName
- the name of the mongo db connectionclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionpipelineQueries
- the aggregation pipeline queries to apply to the change stream. Leave as null if there are no queries- Returns:
- the change stream iterable
- Since:
- 1.0
-
mapReduce
@GloopObjectParameter("mongoDbMapReduceCursor[]:object") public static <T> GloopCursor mapReduce(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, Class<T> resultClass, @NotNull @NotNull String mapFunction, @NotNull @NotNull String reduceFunction, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Aggregates documents according to the specified map-reduce function.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionmapFunction
- A JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduceFunction
- A JavaScript function that "reduces" to a single object all the values associated with acloseClient
- boolean stating whether the cursor will close the mongoDb client after it has been exhausted particular key.- Returns:
- an iterable containing the result of the map-reduce operation
- Since:
- 1.0
-
bulkWrite
@GloopObjectParameter("mongoDbBulkWriteCursor[]:object:::::com.mongodb.client.model.WriteModel") public static GloopCursor bulkWrite(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @GloopParameter(defaultValue="10000") int batchSize, @GloopParameter(defaultValue="false") boolean closeClient, @GloopParameter(defaultValue="false") boolean ordered, Boolean bypassDocumentValidation, GloopExecutionContext context)
Executes a mix of inserts, updates, replaces, and deletes.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled. The eligibility for retryable write support for bulk operations is determined on the whole bulk write. If the
requests
contain anyUpdateManyModels
orDeleteManyModels
then the bulk operation will not support retryable writes.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionbatchSize
- how many write models to cache before sending them to mongo dbcloseClient
- a boolean stating whether to close the client once the cursor has been closed- Returns:
- a gloop output cursor that accepts mongo db write models
- Since:
- 1.0
-
insertOne
public static void insertOne(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull GloopModel document, Boolean bypassDocumentValidation)
Inserts the provided document. If the document is missing an identifier, the driver should generate one.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessiondocument
- the document to insert- Throws:
MongoWriteException
- if the write failed due some other failure specific to the insert commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoCommandException
- if the write failed due to document validation reasonsMongoException
- if the write failed due some other failure- Since:
- 1.0
-
deleteOne
public static DeleteResult deleteOne(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, DeleteOptions options)
Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- the result of the remove one operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the delete commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
deleteOne
public static DeleteResult deleteOne(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, String filterQuery, DeleteOptions options)
Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilterQuery
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- the result of the remove one operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the delete commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
deleteMany
public static DeleteResult deleteMany(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, DeleteOptions options)
Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- the result of the remove many operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the delete commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
deleteMany
public static DeleteResult deleteMany(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, String filterQuery, DeleteOptions options)
Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilterQuery
- the query filter to apply the the delete operationoptions
- the options to apply to the delete operation- Returns:
- the result of the remove many operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the delete commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
replaceOne
public static UpdateResult replaceOne(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, GloopModel replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the replace operation- Returns:
- the result of the replace one operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the replace commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
replaceOne
public static UpdateResult replaceOne(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, String filterQuery, GloopModel replacement, ReplaceOptions options)
Replace a document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilterQuery
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the replace operation- Returns:
- the result of the replace one operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the replace commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
updateOne
public static UpdateResult updateOne(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull org.bson.conversions.Bson filter, @NotNull @NotNull org.bson.conversions.Bson update, UpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the updateOptions to apply to the update operation- Returns:
- the result of the update one operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the update commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
updateOne
public static UpdateResult updateOne(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull String filter, @NotNull @NotNull String update, UpdateOptions updateOptions)
Update a single document in the collection according to the specified arguments.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the updateOptions to apply to the update operation- Returns:
- the result of the update one operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the update commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
updateMany
public static UpdateResult updateMany(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, org.bson.conversions.Bson update, UpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operation- Returns:
- the result of the update many operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the update commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
updateMany
public static UpdateResult updateMany(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, String filter, String update, UpdateOptions updateOptions)
Update all documents in the collection according to the specified arguments.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.updateOptions
- the options to apply to the update operation- Returns:
- the result of the update many operation
- Throws:
MongoWriteException
- if the write failed due some other failure specific to the update commandMongoWriteConcernException
- if the write failed due being unable to fulfil the write concernMongoException
- if the write failed due some other failure- Since:
- 1.0
-
findOneAndDelete
@Nullable public static GloopModel findOneAndDelete(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull org.bson.conversions.Bson filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter to find the document withoptions
- the options to apply to the operation- Returns:
- the document that was removed. If no documents matched the query filter, then null will be returned
- Since:
- 1.0
-
findOneAndDelete
@Nullable public static GloopModel findOneAndDelete(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull String filter, FindOneAndDeleteOptions options)
Atomically find a document and remove it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter to find the document withoptions
- the options to apply to the operation- Returns:
- the document that was removed. If no documents matched the query filter, then null will be returned
- Since:
- 1.0
-
findOneAndReplace
@Nullable public static GloopModel findOneAndReplace(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, org.bson.conversions.Bson filter, GloopModel replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the operation- Returns:
- the document that was replaced. Depending on the value of the
returnOriginal
property, this will either be the document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be returned - Since:
- 1.0
-
findOneAndReplace
@Nullable public static GloopModel findOneAndReplace(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, String filter, GloopModel replacement, FindOneAndReplaceOptions options)
Atomically find a document and replace it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- the query filter to apply the the replace operationreplacement
- the replacement documentoptions
- the options to apply to the operation- Returns:
- the document that was replaced. Depending on the value of the
returnOriginal
property, this will either be the document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be returned - Since:
- 1.0
-
findOneAndUpdate
@Nullable public static GloopModel findOneAndUpdate(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull org.bson.conversions.Bson filter, @NotNull @NotNull org.bson.conversions.Bson update, FindOneAndUpdateOptions options)
Atomically find a document and update it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.options
- the options to apply to the operation- Returns:
- the document that was updated. Depending on the value of the
returnOriginal
property, this will either be the document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be returned - Since:
- 1.0
-
findOneAndUpdate
@Nullable public static GloopModel findOneAndUpdate(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull String filter, @NotNull @NotNull String update, FindOneAndUpdateOptions options)
Atomically find a document and update it.Note: Supports retryable writes on MongoDB server versions 3.6 or higher when the retryWrites setting is enabled.
- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionfilter
- a document describing the query filter, which may not be null.update
- a document describing the update, which may not be null. The update to apply must include only update operators.options
- the options to apply to the operation- Returns:
- the document that was updated. Depending on the value of the
returnOriginal
property, this will either be the document as it was before the update or as it is after the update. If no documents matched the query filter, then null will be returned - Since:
- 1.0
-
createIndex
public static String createIndex(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull org.bson.conversions.Bson keys, IndexOptions indexOptions)
Create an index with the given keys and options.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionkeys
- an object describing the index key(s), which may not be null.indexOptions
- the options for the index- Returns:
- the index name
- Since:
- 1.0
-
createIndex
public static String createIndex(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull String keys, IndexOptions indexOptions)
Create an index with the given keys and options.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionkeys
- an object describing the index key(s), which may not be null.indexOptions
- the options for the index- Returns:
- the index name
- Since:
- 1.0
-
createIndexes
public static List<String> createIndexes(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions)
Create multiple indexes.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionindexes
- the list of indexescreateIndexOptions
- options to use when creating indexes- Returns:
- the list of index names
- Since:
- 1.0
-
listIndexes
public static GloopCursor listIndexes(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @GloopParameter(defaultValue="false") boolean closeClient, GloopExecutionContext context)
Get all the indexes in this collection.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no session- Returns:
- the list indexes iterable interface
- Since:
- 1.0
-
dropIndex
public static void dropIndex(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, @NotNull @NotNull String indexName, DropIndexOptions dropIndexOptions)
Drops the index given its name.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionindexName
- the name of the index to removedropIndexOptions
- the options to use when dropping indexes- Since:
- 1.0
-
dropIndexes
public static void dropIndexes(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, DropIndexOptions dropIndexOptions)
Drop all the indexes on this collection, except for the default on _id.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessiondropIndexOptions
- the options to use when dropping indexes- Since:
- 1.0
-
renameCollection
public static void renameCollection(@NotNull @NotNull String connectionName, @NotNull @NotNull String databaseName, @NotNull @NotNull String collectionName, ClientSession clientSession, MongoNamespace newCollectionNamespace, @GloopParameter(defaultValue="false") boolean dropTarget)
Rename the collection with oldCollectionName to the newCollectionName.- Parameters:
connectionName
- the name of the mongo db connectiondatabaseName
- the database nameclientSession
- the client session with which to associate this operation. Leave as null if there is no sessionnewCollectionNamespace
- the name the collection will be renamed todropTarget
- if mongodb should drop the target of renameCollection prior to renaming the collection.- Throws:
MongoServerException
- if you provide a newCollectionName that is the name of an existing collection and dropTarget is false, or if the oldCollectionName is the name of a collection that doesn't exist- Since:
- 1.0
-
-