Class ReactiveGridFsTemplate
java.lang.Object
org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate
- All Implemented Interfaces:
ReactiveGridFsOperations
ReactiveGridFsOperations implementation to store content into MongoDB GridFS. Uses by default
DefaultDataBufferFactory to create buffers.- Since:
- 2.2
- Author:
- Mark Paluch, Nick Stolwijk, Denis Zavedeev, Christoph Strobl, Mathieu Ouellet
-
Constructor Summary
ConstructorsConstructorDescriptionReactiveGridFsTemplate(DataBufferFactory dataBufferFactory, ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, String bucket) Creates a newReactiveGridFsTemplateusing the givenDataBufferFactory,ReactiveMongoDatabaseFactoryandMongoConverter.ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter) Creates a newReactiveGridFsTemplateusing the givenReactiveMongoDatabaseFactoryandMongoConverter.ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, String bucket) Creates a newReactiveGridFsTemplateusing the givenReactiveMongoDatabaseFactoryandMongoConverter. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.mongodb.client.gridfs.model.GridFSUploadOptionscomputeUploadOptionsFor(String contentType, org.bson.Document metadata) Compute theGridFSUploadOptionsto be used from the given contentType and metadataDocument.<T> reactor.core.publisher.Flux<T>createFlux(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate.ReactiveBucketCallback<T> callback) Create a reusable Flux for aReactiveGridFsTemplate.ReactiveBucketCallback.<T> reactor.core.publisher.Mono<T>createMono(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate.ReactiveBucketCallback<T> callback) Create a reusable Mono for aReactiveGridFsTemplate.ReactiveBucketCallback.reactor.core.publisher.Mono<Void>Deletes all files matching the givenQuery.protected reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.gridfs.GridFSBucket>reactor.core.publisher.Flux<com.mongodb.client.gridfs.model.GridFSFile>Returns aFluxemitting all files matching the given query.reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile>Returns aMonoemitting the fristGridFSFilematching the given query orMono.empty()in case no file matches.reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile>Returns aMonoemitting a singleGridFSFilematching the given query orMono.empty()in case no file matches.protected org.bson.DocumentgetMappedQuery(org.bson.Document query) reactor.core.publisher.Mono<ReactiveGridFsResource>getResource(com.mongodb.client.gridfs.model.GridFSFile file) reactor.core.publisher.Mono<ReactiveGridFsResource>getResource(String location) Returns aMonoemitting theReactiveGridFsResourcewith the given file name.reactor.core.publisher.Flux<ReactiveGridFsResource>getResources(String locationPattern) Returns aFluxemitting allReactiveGridFsResources matching the given file name pattern.reactor.core.publisher.Mono<org.bson.types.ObjectId>store(org.reactivestreams.Publisher<DataBuffer> content, String filename, String contentType, Object metadata) Stores the given content into a file with the given name and content type using the given metadata.<T> reactor.core.publisher.Mono<T>store(GridFsObject<T, org.reactivestreams.Publisher<DataBuffer>> upload) protected org.bson.DocumenttoDocument(Object value) Convert a given value into aDocument.
-
Constructor Details
-
ReactiveGridFsTemplate
Creates a newReactiveGridFsTemplateusing the givenReactiveMongoDatabaseFactoryandMongoConverter.- Parameters:
dbFactory- must not be null.converter- must not be null.
-
ReactiveGridFsTemplate
public ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, @Nullable String bucket) Creates a newReactiveGridFsTemplateusing the givenReactiveMongoDatabaseFactoryandMongoConverter.- Parameters:
dbFactory- must not be null.converter- must not be null.bucket-
-
ReactiveGridFsTemplate
public ReactiveGridFsTemplate(DataBufferFactory dataBufferFactory, ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, @Nullable String bucket) Creates a newReactiveGridFsTemplateusing the givenDataBufferFactory,ReactiveMongoDatabaseFactoryandMongoConverter.- Parameters:
dataBufferFactory- must not be null.dbFactory- must not be null.converter- must not be null.bucket-
-
-
Method Details
-
store
public reactor.core.publisher.Mono<org.bson.types.ObjectId> store(org.reactivestreams.Publisher<DataBuffer> content, @Nullable String filename, @Nullable String contentType, @Nullable Object metadata) Description copied from interface:ReactiveGridFsOperationsStores the given content into a file with the given name and content type using the given metadata. The metadata object will be marshalled before writing.- Specified by:
storein interfaceReactiveGridFsOperations- Parameters:
content- must not be null.filename- must not be null or empty.contentType- can be null.metadata- can be null- Returns:
- a
Monoemitting theObjectIdof theGridFSFilejust created.
-
store
public <T> reactor.core.publisher.Mono<T> store(GridFsObject<T, org.reactivestreams.Publisher<DataBuffer>> upload) Description copied from interface:ReactiveGridFsOperationsStores the givenGridFsObject, likely aGridFsUpload, into into a file with givenname. If theGridFsObject.getFileId()is set, the file will be stored with that id, otherwise the server auto creates a new id.- Specified by:
storein interfaceReactiveGridFsOperations- Type Parameters:
T- id type of the underlyingGridFSFile- Parameters:
upload- theGridFsObject(most likely aGridFsUpload) to be stored.- Returns:
Monoemitting the id of the stored file which is either an auto created value orGridFsObject.getFileId().
-
find
Description copied from interface:ReactiveGridFsOperationsReturns aFluxemitting all files matching the given query.
Note: CurrentlySortcriteria defined at theQuerywill not be regarded as MongoDB does not support ordering for GridFS file access.- Specified by:
findin interfaceReactiveGridFsOperations- Parameters:
query- must not be null.- Returns:
Flux.empty()if no mach found.- See Also:
-
findOne
Description copied from interface:ReactiveGridFsOperationsReturns aMonoemitting a singleGridFSFilematching the given query orMono.empty()in case no file matches.
NOTE If more than one file matches the given query the resultingMonoemits an error. If you want to obtain the first found file useReactiveGridFsOperations.findFirst(Query).- Specified by:
findOnein interfaceReactiveGridFsOperations- Parameters:
query- must not be null.- Returns:
Mono.empty()if not match found.
-
findFirst
public reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile> findFirst(Query query) Description copied from interface:ReactiveGridFsOperationsReturns aMonoemitting the fristGridFSFilematching the given query orMono.empty()in case no file matches.- Specified by:
findFirstin interfaceReactiveGridFsOperations- Parameters:
query- must not be null.- Returns:
Mono.empty()if not match found.
-
delete
Description copied from interface:ReactiveGridFsOperationsDeletes all files matching the givenQuery.- Specified by:
deletein interfaceReactiveGridFsOperations- Parameters:
query- must not be null.- Returns:
- a
Monosignalling operation completion.
-
getResource
Description copied from interface:ReactiveGridFsOperationsReturns aMonoemitting theReactiveGridFsResourcewith the given file name.- Specified by:
getResourcein interfaceReactiveGridFsOperations- Parameters:
location- must not be null.- Returns:
Mono.empty()if no match found.
-
getResource
public reactor.core.publisher.Mono<ReactiveGridFsResource> getResource(com.mongodb.client.gridfs.model.GridFSFile file) Description copied from interface:ReactiveGridFsOperations- Specified by:
getResourcein interfaceReactiveGridFsOperations- Parameters:
file- must not be null.- Returns:
Mono.empty()if no match found.
-
getResources
Description copied from interface:ReactiveGridFsOperationsReturns aFluxemitting allReactiveGridFsResources matching the given file name pattern.- Specified by:
getResourcesin interfaceReactiveGridFsOperations- Parameters:
locationPattern- must not be null.- Returns:
Flux.empty()if no match found.
-
createMono
public <T> reactor.core.publisher.Mono<T> createMono(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate.ReactiveBucketCallback<T> callback) Create a reusable Mono for aReactiveGridFsTemplate.ReactiveBucketCallback. It's up to the developer to choose to obtain a newFluxor to reuse theFlux.- Parameters:
callback- must not be null- Returns:
- a
Monowrapping theReactiveGridFsTemplate.ReactiveBucketCallback.
-
createFlux
public <T> reactor.core.publisher.Flux<T> createFlux(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate.ReactiveBucketCallback<T> callback) Create a reusable Flux for aReactiveGridFsTemplate.ReactiveBucketCallback. It's up to the developer to choose to obtain a newFluxor to reuse theFlux.- Parameters:
callback- must not be null- Returns:
- a
Fluxwrapping theReactiveGridFsTemplate.ReactiveBucketCallback.
-
doGetBucket
protected reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.gridfs.GridFSBucket> doGetBucket() -
getMappedQuery
protected org.bson.Document getMappedQuery(org.bson.Document query) - Parameters:
query- pass the given query though aQueryMapperto apply type conversion.- Returns:
- never null.
-
computeUploadOptionsFor
protected com.mongodb.client.gridfs.model.GridFSUploadOptions computeUploadOptionsFor(@Nullable String contentType, @Nullable org.bson.Document metadata) Compute theGridFSUploadOptionsto be used from the given contentType and metadataDocument.- Parameters:
contentType- can be null.metadata- can be null- Returns:
- never null.
-
toDocument
Convert a given value into aDocument.- Parameters:
value- can be null.- Returns:
- an empty
Documentif the source value is null.
-