/** * Removes all the objects that match the a given optional query. If query is not specified, all * objects are removed. However, please notice that this is normally less performant that dropping * the collection and creating it and its indices again * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:remove-objects} * * @param collection the collection whose elements will be removed * @param query the optional {@link DBObject} query object. Objects that match it will be removed. * @param writeConcern the write concern used to remove the object */ @Processor public void removeObjects( String collection, @Optional @Default("#[payload]") DBObject query, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { client.removeObjects(collection, query, writeConcern); }
/** * Inserts or updates an object based on its object _id. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:save-object} * * @param collection the collection where to insert the object * @param element the mandatory {@link DBObject} object to insert. * @param writeConcern the write concern used to persist the object */ @Processor public void saveObject( String collection, @Optional @Default("#[payload]") DBObject element, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { client.saveObject(collection, from(element), writeConcern); }
/** * Removes all the objects that match the a given optional query. If query is not specified, all * objects are removed. However, please notice that this is normally less performant that dropping * the collection and creating it and its indices again * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:remove-using-query-map} * * @param collection the collection whose elements will be removed * @param queryAttributes the query object. Objects that match it will be removed. * @param writeConcern the write concern used to remove the object */ @Processor public void removeUsingQueryMap( String collection, @Placement(group = "Query Attributes") Map<String, Object> queryAttributes, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { client.removeObjects(collection, (DBObject) adapt(queryAttributes), writeConcern); }
/** * Inserts an object in a collection, setting its id if necessary. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:insert-object} * * @param collection the name of the collection where to insert the given object * @param dbObject a {@link DBObject} instance. * @param writeConcern the optional write concern of insertion * @return the id that was just insterted */ @Processor public String insertObject( String collection, @Optional @Default("#[payload]") DBObject dbObject, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { return client.insertObject(collection, dbObject, writeConcern); }
/** * Finds the first object that matches a given query. Throws a {@link MongoException} if no one * matches the given query * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:find-one-object-using-query-map} * * @param collection the target collection * @param queryAttributes the mandatory query object that the returned object matches. * @param fields alternative way of passing fields as a literal List * @return a non-null {@link DBObject} that matches the query. */ @Processor public DBObject findOneObjectUsingQueryMap( String collection, @Placement(group = "Query Attributes") Map<String, Object> queryAttributes, @Placement(group = "Fields") @Optional List<String> fields) { return client.findOneObject(collection, (DBObject) adapt(queryAttributes), fields); }
/** * Inserts or updates an object based on its object _id. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:save-object-from-map} * * @param collection the collection where to insert the object * @param elementAttributes the mandatory object to insert. * @param writeConcern the write concern used to persist the object */ @Processor public void saveObjectFromMap( String collection, @Placement(group = "Element Attributes") Map<String, Object> elementAttributes, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { client.saveObject(collection, (DBObject) adapt(elementAttributes), writeConcern); }
/** * Finds the first object that matches a given query. Throws a {@link MongoException} if no one * matches the given query * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:find-one-object} * * @param collection the target collection * @param query the mandatory {@link DBObject} query object that the returned object matches. * @param fields alternative way of passing fields as a literal List * @return a non-null {@link DBObject} that matches the query. */ @Processor public DBObject findOneObject( String collection, @Optional @Default("#[payload]") DBObject query, @Placement(group = "Fields") @Optional List<String> fields) { return client.findOneObject(collection, query, fields); }
/** * Creates a new collection. If the collection already exists, a MongoException will be thrown. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:create-collection} * * @param collection the name of the collection to create * @param capped if the collection will be capped * @param maxObjects the maximum number of documents the new collection is able to contain * @param size the maximum size of the new collection */ @Processor public void createCollection( String collection, @Optional @Default(CAPPED_DEFAULT_VALUE) boolean capped, @Optional Integer maxObjects, @Optional Integer size) { client.createCollection(collection, capped, maxObjects, size); }
/** * 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. * * <p>Each supplied function is coded in JavaScript. * * <p>Note that the correct way of writing those functions may not be obvious; please consult * MongoDB documentation for writing them. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:map-reduce-objects} * * @param collection the name of the collection to map and reduce * @param mapFunction a JavaScript encoded mapping function * @param reduceFunction a JavaScript encoded reducing function * @param outputCollection 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. * @return an iterable that retrieves the resulting collection of {@link DBObject} */ @Processor public Iterable<DBObject> mapReduceObjects( String collection, String mapFunction, String reduceFunction, @Optional String outputCollection) { return client.mapReduceObjects(collection, mapFunction, reduceFunction, outputCollection); }
/** * Finds all objects that match a given query. If no query is specified, all objects of the * collection are retrieved. If no fields object is specified, all fields are retrieved. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:find-objects} * * @param collection the target collection * @param query the optional {@link DBObject} query object. If unspecified, all documents are * returned. * @param fields alternative way of passing fields as a literal List * @param numToSkip number of objects skip (offset) * @param limit limit of objects to return * @return an iterable of {@link DBObject} */ @Processor public Iterable<DBObject> findObjects( String collection, @Optional @Default("") DBObject query, @Placement(group = "Fields") @Optional List<String> fields, @Optional Integer numToSkip, @Optional Integer limit) { return client.findObjects(collection, query, fields, numToSkip, limit); }
/** * Updates objects that matches the given query. If parameter multi is set to false, only the * first document matching it will be updated. Otherwise, all the documents matching it will be * updated. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:update-objects} * * @param collection the name of the collection to update * @param query the {@link DBObject} query object used to detect the element to update. * @param element the {@link DBObject} mandatory object that will replace that one which matches * the query. * @param upsert if the database should create the element if it does not exist * @param multi if all or just the first object matching the query will be updated * @param writeConcern the write concern used to update */ @Processor public void updateObjects( String collection, DBObject query, @Optional @Default("#[payload]") DBObject element, @Optional @Default(CAPPED_DEFAULT_VALUE) boolean upsert, @Optional @Default("true") boolean multi, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { client.updateObjects(collection, query, element, upsert, multi, writeConcern); }
/** * Finds all objects that match a given query. If no query is specified, all objects of the * collection are retrieved. If no fields object is specified, all fields are retrieved. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:find-objects-using-query-map} * * @param collection the target collection * @param queryAttributes the optional query object. If unspecified, all documents are returned. * @param fields alternative way of passing fields as a literal List * @param numToSkip number of objects skip (offset) * @param limit limit of objects to return * @return an iterable of {@link DBObject} */ @Processor public Iterable<DBObject> findObjectsUsingQueryMap( String collection, @Placement(group = "Query Attributes") @Optional Map<String, Object> queryAttributes, @Placement(group = "Fields") @Optional List<String> fields, @Optional Integer numToSkip, @Optional Integer limit) { return client.findObjects( collection, (DBObject) adapt(queryAttributes), fields, numToSkip, limit); }
/** * Updates objects that matches the given query. If parameter multi is set to false, only the * first document matching it will be updated. Otherwise, all the documents matching it will be * updated. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:update-objects-using-query-map} * * @param collection the name of the collection to update * @param queryAttributes the query object used to detect the element to update. * @param element the {@link DBObject} mandatory object that will replace that one which matches * the query. * @param upsert if the database should create the element if it does not exist * @param multi if all or just the first object matching the query will be updated * @param writeConcern the write concern used to update */ @Processor public void updateObjectsUsingQueryMap( String collection, Map<String, Object> queryAttributes, DBObject element, @Optional @Default(CAPPED_DEFAULT_VALUE) boolean upsert, @Optional @Default("true") boolean multi, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { client.updateObjects( collection, (DBObject) adapt(queryAttributes), element, upsert, multi, writeConcern); }
/** * Update objects using a mongo function * * <p> * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:update-objects-by-function} * * @param collection the name of the collection to update * @param function the function used to execute the update * @param query the {@link DBObject} query object used to detect the element to update. * @param element the {@link DBObject} mandatory object that will replace that one which matches * the query. * @param upsert if the database should create the element if it does not exist * @param multi if all or just the first object matching the query will be updated * @param writeConcern the write concern used to update */ @Processor public void updateObjectsByFunction( String collection, String function, DBObject query, DBObject element, @Optional @Default(CAPPED_DEFAULT_VALUE) boolean upsert, @Optional @Default(value = "true") boolean multi, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { DBObject functionDbObject = fromFunction(function, element); client.updateObjects(collection, query, functionDbObject, upsert, multi, writeConcern); }
/** * Creates a new GridFSFile in the database, saving the given content, filename, contentType, and * extraData, and answers it. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:create-file-from-payload} * * @param payload the mandatory content of the new gridfs file. It may be a java.io.File, a byte[] * or an InputStream. * @param filename the mandatory name of new file. * @param contentType the optional content type of the new file * @param metadata the optional {@link DBObject} metadata of the new content type * @return the new GridFSFile {@link DBObject} * @throws IOException IOException */ @Processor public DBObject createFileFromPayload( @Payload Object payload, String filename, @Optional String contentType, @Optional DBObject metadata) throws IOException { InputStream stream = toStream(payload); try { return client.createFile(stream, filename, contentType, metadata); } finally { stream.close(); } }
/** * Update objects using a mongo function * * <p> * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample * mongo:update-objects-by-function-using-map} * * @param collection the name of the collection to update * @param function the function used to execute the update * @param queryAttributes the query object used to detect the element to update. * @param elementAttributes the mandatory object that will replace that one which matches the * query. * @param upsert if the database should create the element if it does not exist * @param multi if all or just the first object matching the query will be updated * @param writeConcern the write concern used to update */ @Processor public void updateObjectsByFunctionUsingMap( String collection, String function, Map<String, Object> queryAttributes, Map<String, Object> elementAttributes, @Optional @Default(CAPPED_DEFAULT_VALUE) boolean upsert, @Optional @Default(value = "true") boolean multi, @Optional @Default(WRITE_CONCERN_DEFAULT_VALUE) WriteConcern writeConcern) { DBObject functionDbObject = fromFunction(function, (DBObject) adapt(elementAttributes)); client.updateObjects( collection, (DBObject) adapt(queryAttributes), functionDbObject, upsert, multi, writeConcern); }
/** * Answers an inputstream to the contents of the first file that matches the given query. If no * object matches it, a MongoException is thrown. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:get-file-content} * * @param query the {@link DBObject} mandatory query * @return an InputStream to the file contents */ @Processor public InputStream getFileContent(@Optional @Default("#[payload]") DBObject query) { return client.getFileContent(from(query)); }
/** * Answers the first file that matches the given query. If no object matches it, a MongoException * is thrown. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:find-one-file-using-query-map} * * @param queryAttributes the mandatory query * @return a {@link DBObject} */ @Processor public DBObject findOneFileUsingQueryMap( @Placement(group = "Query Attributes") Map<String, Object> queryAttributes) { return client.findOneFile((DBObject) adapt(queryAttributes)); }
/** * Answers the first file that matches the given query. If no object matches it, a MongoException * is thrown. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:find-one-file} * * @param query the {@link DBObject} mandatory query * @return a {@link DBObject} */ @Processor public DBObject findOneFile(DBObject query) { return client.findOneFile(from(query)); }
/** * Removes all the files that match the given query. If no query is specified, all files are * removed * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:remove-files-using-query-map} * * @param queryAttributes the optional query */ @Processor public void removeFilesUsingQueryMap( @Placement(group = "Query Attributes") @Optional Map<String, Object> queryAttributes) { client.removeFiles((DBObject) adapt(queryAttributes)); }
/** * Lists all the files that match the given query, sorting them by filename. If no query is * specified, all files are listed. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:list-files-using-query-map} * * @param queryAttributes the optional query * @return an iterable of {@link DBObject} */ @Processor public Iterable<DBObject> listFilesUsingQueryMap( @Placement(group = "Query Attributes") @Optional Map<String, Object> queryAttributes) { return client.listFiles((DBObject) adapt(queryAttributes)); }
/** * Counts the number of objects that match the given query. If no query is passed, returns the * number of elements in the collection * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:count-objects-using-query-map} * * @param collection the target collection * @param queryAttributes the optional query for counting objects. Only objects matching it will * be counted. If unspecified, all objects are counted. * @return the amount of objects that matches the query */ @Processor public long countObjectsUsingQueryMap( String collection, @Placement(group = "Query Attributes") @Optional Map<String, Object> queryAttributes) { return client.countObjects(collection, (DBObject) adapt(queryAttributes)); }
/** * Counts the number of objects that match the given query. If no query is passed, returns the * number of elements in the collection * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:count-objects} * * @param collection the target collection * @param query the optional {@link DBObject} query for counting objects. Only objects matching it * will be counted. If unspecified, all objects are counted. * @return the amount of objects that matches the query */ @Processor public long countObjects(String collection, @Optional @Default("#[payload]") DBObject query) { return client.countObjects(collection, query); }
/** * Answers an inputstream to the contents of the first file that matches the given * queryAttributes. If no object matches it, a MongoException is thrown. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:get-file-content-using-query-map} * * @param queryAttributes the mandatory query attributes * @return an InputStream to the file contents */ @Processor public InputStream getFileContentUsingQueryMap( @Placement(group = "Query Attributes") Map<String, Object> queryAttributes) { return client.getFileContent((DBObject) adapt(queryAttributes)); }
/** * Lists all the files that match the given query, sorting them by filename. If no query is * specified, all files are listed. * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:list-files} * * @param query the {@link DBObject} optional query * @return an iterable of {@link DBObject} */ @Processor public Iterable<DBObject> listFiles(@Optional @Default("#[payload]") DBObject query) { return client.listFiles(from(query)); }
/** * Creates a new index * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:create-index} * * @param collection the name of the collection where the index will be created * @param field the name of the field which will be indexed * @param order the indexing order */ @Processor public void createIndex( String collection, String field, @Optional @Default("ASC") IndexOrder order) { client.createIndex(collection, field, order); }
/** * Removes all the files that match the given query. If no query is specified, all files are * removed * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:remove-files} * * @param query the {@link DBObject} optional query */ @Processor public void removeFiles(@Optional @Default("#[payload]") DBObject query) { client.removeFiles(from(query)); }
/** * Drops an existing index * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:drop-index} * * @param collection the name of the collection where the index is * @param index the name of the index to drop */ @Processor public void dropIndex(String collection, String index) { client.dropIndex(collection, index); }
/** * Executes a command on the database * * <p> * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:remove-files} * * @param commandName The command to execute on the database * @param commandValue The value for the command * @return The result of the command */ @Processor public DBObject executeCommand(String commandName, @Optional String commandValue) { DBObject dbObject = fromCommand(commandName, commandValue); return client.executeComamnd(dbObject); }
/** * List existent indices in a collection * * <p>{@sample.xml ../../../doc/mongo-connector.xml.sample mongo:list-indices} * * @param collection the name of the collection * @return a collection of {@link DBObject} with indices information */ @Processor public Collection<DBObject> listIndices(String collection) { return client.listIndices(collection); }