@Connector(name="mongo", schemaVersion="2.0", friendlyName="Mongo DB", minMuleVersion="3.6") @ReconnectOn(exceptions=java.lang.IllegalStateException.class) @RequiresEnterpriseLicense(allowEval=true) public class MongoCloudConnector extends Object
Constructor and Description |
---|
MongoCloudConnector() |
Modifier and Type | Method and Description |
---|---|
org.bson.Document |
addUser(String newUsername,
String newPassword)
Adds a new user for this db
|
long |
countDocuments(String collection,
org.bson.Document query)
Counts the number of documents that match the given query.
|
void |
createCollection(String collection,
boolean capped,
Integer maxObjects,
Integer size)
Creates a new collection.
|
com.mongodb.client.gridfs.model.GridFSFile |
createFileFromPayload(Object payload,
String filename,
org.bson.Document metadata)
Creates a new GridFSFile in the database, saving the given content, filename, contentType, and extraData, and answers it.
|
void |
createIndex(String collection,
String field,
IndexOrder order)
Creates a new index
|
void |
dropCollection(String collection)
Deletes a collection and all the objects it contains.
|
void |
dropDatabase()
Drop the current database
|
void |
dropIndex(String collection,
String index)
Drops an existing index
|
void |
dump(String outputDirectory,
String outputName,
boolean zip,
boolean oplog,
int threads)
Executes a dump of the database to the specified output directory.
|
org.bson.Document |
executeCommand(String commandName,
String commandValue)
Executes a command on the database
|
boolean |
existsCollection(String collection)
Answers if a collection exists given its name
|
Iterable<org.bson.Document> |
findDocuments(String collection,
org.bson.Document query,
List<String> fields,
Integer numToSkip,
Integer limit,
org.bson.Document sortBy,
boolean returnId)
Finds all documents that match a given query.
|
Iterable<com.mongodb.client.gridfs.model.GridFSFile> |
findFiles(org.bson.Document query)
Lists all the files that match the given query
|
org.bson.Document |
findOneAndUpdateDocument(String collection,
org.bson.Document query,
org.bson.Document element,
List<String> fields,
Boolean returnNewDocument,
org.bson.Document sortBy,
boolean remove,
boolean upsert,
boolean bypassDocumentValidation,
boolean returnId)
Finds and update the first document that matches a given query.
|
org.bson.Document |
findOneDocument(String collection,
org.bson.Document query,
List<String> fields,
Boolean failOnNotFound,
boolean returnId)
Finds the first document that matches a given query.
|
com.mongodb.client.gridfs.model.GridFSFile |
findOneFile(org.bson.Document query)
Answers the first file that matches the given query.
|
AbstractConfig |
getConfig() |
InputStream |
getFileContent(org.bson.BsonObjectId fileId)
Answers an inputstream to the contents of the first file that matches the given query.
|
void |
incrementalDump(String outputDirectory,
String incrementalTimestampFile)
Executes an incremental dump of the database
|
String |
insertDocument(String collection,
org.bson.Document document)
Deprecated.
|
org.bson.Document |
insertDocuments(String collection,
List<org.bson.Document> documents,
boolean ordered)
Inserts a list of documents in a collection, setting its id if necessary.
|
Iterable<String> |
listCollections()
Lists names of collections available at this database
|
Iterable<com.mongodb.client.gridfs.model.GridFSFile> |
listFiles(org.bson.Document query)
Lists all the files that match the given query, sorting them by filename.
|
Collection<org.bson.Document> |
listIndices(String collection)
List existent indices in a collection
|
Iterable<org.bson.Document> |
mapReduceObjects(String collection,
String mapFunction,
String reduceFunction,
String outputCollection)
Transforms a collection into a collection of aggregated groups, by applying a supplied element-mapping function to each element, that transforms each one into a key-value
pair, grouping the resulting pairs by key, and finally reducing values in each group applying a suppling 'reduce' function.
|
static org.mule.api.transformer.Transformer |
mongoTransformerResolver(org.mule.api.transformer.DataType<?> source,
org.mule.api.transformer.DataType<?> result,
org.mule.api.MuleContext muleContext) |
void |
removeDocuments(String collection,
org.bson.Document query)
Removes all the documents that match the a given optional query.
|
void |
removeFiles(org.bson.BsonObjectId fileId)
Removes the file that matches the given file id.
|
void |
restore(String inputPath,
boolean drop,
boolean oplogReplay)
Takes the output from the dump and restores it.
|
void |
saveDocument(String collection,
org.bson.Document document)
Inserts or updates a document based on its object _id.
|
void |
setConfig(AbstractConfig config) |
org.bson.Document |
updateDocuments(String collection,
org.bson.Document query,
org.bson.Document element,
boolean multi)
Updates documents that matches the given query.
|
org.bson.Document |
updateDocumentsByFunction(String collection,
String function,
org.bson.Document query,
org.bson.Document element,
boolean upsert,
boolean multi)
Update documents using a Mongo function.
|
org.bson.Document |
updateDocumentsByFunctions(String collection,
org.bson.Document query,
org.bson.Document functions,
boolean upsert,
boolean multi)
Update documents using one or more mongo function(s).
|
public AbstractConfig getConfig()
public void setConfig(AbstractConfig config)
@Processor public org.bson.Document addUser(String newUsername, String newPassword)
newUsername
- Name of the usernewPassword
- Password that will be used for authentication@Processor public void dropDatabase()
@Processor public Iterable<String> listCollections()
@Processor public boolean existsCollection(@Default(value="#[payload]") String collection)
collection
- the name of the collection@Processor public void dropCollection(@Default(value="#[payload]") String collection)
collection
- the name of the collection to drop@Processor public void createCollection(String collection, @Default(value="false") boolean capped, @Optional Integer maxObjects, @Optional Integer size)
collection
- the name of the collection to createcapped
- if the collection will be cappedmaxObjects
- the maximum number of documents the new collection is able to containsize
- the maximum size of the new collection@Processor @Deprecated public String insertDocument(String collection, @RefOnly @Default(value="#[payload]") org.bson.Document document)
insertDocuments(java.lang.String, java.util.List<org.bson.Document>, boolean)
insteadcollection
- the name of the collection where to insert the given document.document
- a Document
instance.@Processor public org.bson.Document insertDocuments(String collection, @RefOnly @Default(value="#[payload]") List<org.bson.Document> documents, @Default(value="true") boolean ordered)
collection
- the name of the collection where to insert the given document.documents
- a List
of Document
.ordered
- indicates if the list of write operations is ordered or unordered. By default, if an error occurs during the processing of one of the write operations, MongoDB will return without processing any remaining write operations in the list.Document
with the operation result@Processor public org.bson.Document updateDocuments(String collection, @RefOnly @Optional org.bson.Document query, @RefOnly @Default(value="#[payload]") org.bson.Document element, @Default(value="true") boolean multi)
collection
- the name of the collection to updatequery
- the Document
query object used to detect the element to update.element
- the Document
mandatory object that will replace that one which matches the query.multi
- if all or just the first document matching the query will be updatedDocument
with the update status@Processor public org.bson.Document updateDocumentsByFunction(String collection, String function, @RefOnly @Optional org.bson.Document query, @RefOnly @Default(value="#[payload]") org.bson.Document element, @Default(value="false") boolean upsert, @Default(value="true") boolean multi)
Update documents using a Mongo function. If query is not specified, all documents are retrieved.
collection
- the name of the collection to updatefunction
- the function used to execute the updatequery
- the Document
query document used to detect the element to update.element
- the Document
mandatory document that will replace that one which matches the query.upsert
- if the database should create the element if it does not exist.multi
- if all or just the first document matching the query will be updated.Document
with the update status.@Processor public org.bson.Document updateDocumentsByFunctions(String collection, @RefOnly @Optional org.bson.Document query, @RefOnly @Default(value="#[payload]") org.bson.Document functions, @Default(value="false") boolean upsert, @Default(value="true") boolean multi)
Update documents using one or more mongo function(s). If query is not specified, all documents are retrieved. If there are duplicated operators. Only the last one will be executed.
collection
- the name of the collection to updatequery
- the Document
query document used to detect the element to updatefunctions
- the Document
of functions used to execute the update. e.g. %3c$set,{"key":123}%3eupsert
- whether the database should create the element if it does not existmulti
- if all or just the first document matching the query will be updatedDocument
with the update status.@Processor public void saveDocument(String collection, @RefOnly @Default(value="#[payload]") org.bson.Document document)
collection
- the collection where to insert the objectdocument
- the mandatory Document
document to insert.@Processor public void removeDocuments(String collection, @RefOnly @Default(value="#[payload]") org.bson.Document query)
collection
- the collection whose elements will be removedquery
- the optional Document
query object. Documents that match it will be removed.@Processor public Iterable<org.bson.Document> mapReduceObjects(String collection, String mapFunction, String reduceFunction, @Optional String outputCollection)
Each supplied function is coded in JavaScript.
Note that the correct way of writing those functions may not be obvious; please consult MongoDB documentation for writing them.collection
- the name of the collection to map and reducemapFunction
- a JavaScript encoded mapping functionreduceFunction
- a JavaScript encoded reducing functionoutputCollection
- the name of the output collection to write the results, replacing previous collection if existed, mandatory when results may be larger than 16MB. If
outputCollection is unspecified, the computation is performed in-memory and not persisted.Document
@Processor public long countDocuments(String collection, @RefOnly @Default(value="#[payload]") org.bson.Document query)
collection
- the target collectionquery
- the optional Document
query for counting documents. Only documents matching it will be counted. If unspecified, all documents are counted.@Processor public Iterable<org.bson.Document> findDocuments(String collection, @RefOnly @Default(value="#[payload]") org.bson.Document query, @Placement(group="Fields") @Optional List<String> fields, @Optional Integer numToSkip, @Optional Integer limit, @RefOnly @Optional org.bson.Document sortBy, @FriendlyName(value="Return _id field") @Default(value="true") boolean returnId)
collection
- the target collectionquery
- the optional Document
query document. If unspecified, all documents are returned.fields
- alternative way of passing fields as a literal ListnumToSkip
- number of documents skip (offset)limit
- limit of documents to returnsortBy
- indicates the Document
used to sort the resultsreturnId
- indicates if the _id field should be returned. Default value is true.Document
@Processor public org.bson.Document findOneDocument(String collection, @RefOnly @Default(value="#[payload]") org.bson.Document query, @Placement(group="Fields") @Optional List<String> fields, @Default(value="true") Boolean failOnNotFound, @FriendlyName(value="Return _id field") @Default(value="true") boolean returnId)
MongoException
if no one matches the given querycollection
- the target collectionquery
- the mandatory Document
query document that the returned object matches.fields
- alternative way of passing fields as a literal ListfailOnNotFound
- Flag to specify if an exception will be thrown when no object is found. For backward compatibility the default value is true.returnId
- indicates if the _id field should be returned. Default value is true.Document
that matches the query. If nothing matches and the failOnNotFound is set to false, null will be returned@Processor public org.bson.Document findOneAndUpdateDocument(String collection, @RefOnly @Optional org.bson.Document query, @RefOnly @Default(value="#[payload]") org.bson.Document element, @Placement(group="Fields to return") @Optional List<String> fields, @Placement(group="Fields to return") @Default(value="false") Boolean returnNewDocument, @RefOnly @Optional org.bson.Document sortBy, @Default(value="false") boolean remove, @Default(value="false") boolean upsert, @Default(value="false") boolean bypassDocumentValidation, @FriendlyName(value="Return _id field") @Default(value="true") boolean returnId)
collection
- the target collectionquery
- the Document
query that the returned object matches.element
- the Document
mandatory object that will replace that one which matches the queryfields
- alternative way of passing fields as a literal ListreturnNewDocument
- Flag to specify if the returning Document
should be the updated document instead of the original. Defaults to false, returning the document
before modificationssortBy
- indicates the Document
used to sort the results.remove
- removes the Document
specified in the query field. Defaults to falseupsert
- whether the database should create the element if it does not existbypassDocumentValidation
- lets you update documents that do not meet the validation requirements. Defaults to falsereturnId
- indicates if the _id field should be returned. Default value is true.Document
that matches the query. If nothing matches, null will be returned@Processor public void createIndex(String collection, String field, @Default(value="ASC") IndexOrder order)
collection
- the name of the collection where the index will be createdfield
- the name of the field which will be indexedorder
- the indexing order@Processor public void dropIndex(String collection, String index)
collection
- the name of the collection where the index isindex
- the name of the index to drop@Processor public Collection<org.bson.Document> listIndices(String collection)
collection
- the name of the collectionDocument
with indices information@Processor public com.mongodb.client.gridfs.model.GridFSFile createFileFromPayload(@RefOnly @Default(value="#[payload]") Object payload, String filename, @RefOnly @Optional org.bson.Document metadata) throws IOException
payload
- the mandatory content of the new gridfs file. It may be a java.io.File, a byte[] or an InputStream.filename
- the mandatory name of new file.metadata
- the optional Document
metadata of the new content typeGridFSFile
IOException
- if the file could not be found@Processor @NoMetaData public Iterable<com.mongodb.client.gridfs.model.GridFSFile> findFiles(@RefOnly @Default(value="#[payload]") org.bson.Document query)
query
- a Document
queryGridFSFile
files iterable@Processor @NoMetaData public com.mongodb.client.gridfs.model.GridFSFile findOneFile(@RefOnly @Default(value="#[payload]") org.bson.Document query)
query
- the Document
mandatory queryGridFSFile
@Processor @NoMetaData public InputStream getFileContent(@RefOnly @Default(value="#[payload]") org.bson.BsonObjectId fileId)
fileId
- the BsonObjectId of the file to be deleted@Processor @NoMetaData public Iterable<com.mongodb.client.gridfs.model.GridFSFile> listFiles(@RefOnly @Default(value="#[payload]") org.bson.Document query)
query
- the Document
optional queryGridFSFile
@Processor @NoMetaData public void removeFiles(@RefOnly @Default(value="#[payload]") org.bson.BsonObjectId fileId)
Removes the file that matches the given file id. If no file id is specified, all files are removed
fileId
- the BsonObjectId of the file to be deleted@Processor public org.bson.Document executeCommand(@Optional String commandName, @Optional String commandValue)
Executes a command on the database
commandName
- The command to execute on the database. If the whole command is sent in the commandValue parameter, set commandName to blank.commandValue
- The value for the command, or the whole command itself, as a document.@Processor public void dump(@Default(value="dump") String outputDirectory, @Optional String outputName, @Default(value="false") boolean zip, @Default(value="false") boolean oplog, @Default(value="5") int threads) throws IOException
outputDirectory
- output directory path, if no output directory is provided the default /dump directory is assumedoutputName
- output file name, if it's not specified the database name is usedzip
- whether to zip the created dump file or notoplog
- point in time backup (requires an oplog)threads
- amount of threads to execute the dumpIOException
- if an error occurs during the dump@Processor public void incrementalDump(@Default(value="dump") String outputDirectory, @Optional String incrementalTimestampFile) throws IOException
Executes an incremental dump of the database
outputDirectory
- output directory path, if no output directory is provided the default /dump directory is assumedincrementalTimestampFile
- file that keeps track of the last timestamp processed, if no file is provided one is created on the output directoryIOException
- if an error occurs during the incremental dump@Processor public void restore(@Default(value="dump") String inputPath, @Default(value="false") boolean drop, @Default(value="false") boolean oplogReplay) throws IOException
inputPath
- input path to the dump files, it can be a directory, a zip file or just a bson filedrop
- whether to drop existing collections before restoreoplogReplay
- replay oplog for point-in-time restoreIOException
- if an error occurs during restore of the database@TransformerResolver public static org.mule.api.transformer.Transformer mongoTransformerResolver(org.mule.api.transformer.DataType<?> source, org.mule.api.transformer.DataType<?> result, org.mule.api.MuleContext muleContext) throws org.mule.api.MuleException
org.mule.api.MuleException
Copyright © 2010–2021. All rights reserved.