@Connector(name="mongo", schemaVersion="2.0", friendlyName="Mongo DB", minMuleVersion="3.6") @ReconnectOn(exceptions=java.lang.IllegalStateException.class) @RequiresEnterpriseLicense 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.conversions.Bson 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.DBObject |
createFileFromPayload(Object payload,
String filename,
String contentType,
com.mongodb.DBObject 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)
Finds all documents that match a given query.
|
Iterable<com.mongodb.DBObject> |
findFiles(com.mongodb.DBObject query)
Lists all the files that match the given query
|
org.bson.Document |
findOneDocument(String collection,
org.bson.Document query,
List<String> fields,
Boolean failOnNotFound)
Finds the first document that matches a given query.
|
com.mongodb.DBObject |
findOneFile(com.mongodb.DBObject query)
Answers the first file that matches the given query.
|
Config |
getConfig() |
InputStream |
getFileContent(com.mongodb.DBObject query)
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)
Inserts a document in a collection, setting its id if necessary.
|
Iterable<String> |
listCollections()
Lists names of collections available at this database
|
Iterable<com.mongodb.DBObject> |
listFiles(com.mongodb.DBObject 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(com.mongodb.DBObject query)
Removes all the files that match the given query.
|
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(Config 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.
|
public Config getConfig()
public void setConfig(Config 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 public String insertDocument(String collection, @RefOnly@Default(value="#[payload]") org.bson.Document document)
collection
- the name of the collection where to insert the given document.document
- a Document
instance.@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)
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 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)
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.conversions.Bson 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, @Default(value="#[payload]")@RefOnly org.bson.Document query, @Placement(group="Fields")@Optional List<String> fields, @Optional Integer numToSkip, @Optional Integer limit, @RefOnly@Optional org.bson.Document sortBy)
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 resultsDocument
@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)
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.Document
that matches the query. If nothing matches and the failOnNotFound is set to false, 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.DBObject createFileFromPayload(@Default(value="#[payload]")@RefOnly Object payload, String filename, @Optional String contentType, @RefOnly@Optional com.mongodb.DBObject 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.contentType
- the optional content type of the new filemetadata
- the optional Document
metadata of the new content typeDBObject
IOException
- IOException@Processor @NoMetaData public Iterable<com.mongodb.DBObject> findFiles(@RefOnly@Default(value="#[payload]") com.mongodb.DBObject query)
query
- a DBObject
query the optional queryDBObject
files iterable@Processor @NoMetaData public com.mongodb.DBObject findOneFile(@RefOnly@Default(value="#[payload]") com.mongodb.DBObject query)
query
- the DBObject
mandatory queryDBObject
@Processor @NoMetaData public InputStream getFileContent(@RefOnly@Default(value="#[payload]") com.mongodb.DBObject query)
query
- the DBObject
mandatory query@Processor @NoMetaData public Iterable<com.mongodb.DBObject> listFiles(@RefOnly@Default(value="#[payload]") com.mongodb.DBObject query)
query
- the DBObject
optional queryDBObject
@Processor @NoMetaData public void removeFiles(@RefOnly@Default(value="#[payload]") com.mongodb.DBObject query)
query
- the DBObject
optional query@Processor public org.bson.Document executeCommand(String commandName, @Optional String commandValue)
commandName
- The command to execute on the databasecommandValue
- The value for the command@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
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–2015. All rights reserved.