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(MongoConverter converter, Mono<com.mongodb.reactivestreams.client.gridfs.GridFSBucket> gridFSBucket, DataBufferFactory dataBufferFactory) Creates a newReactiveGridFsTemplateusing the givenMongoConverter,Monoemitting aReactiveMongoDatabaseFactoryandDataBufferFactory.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> Flux<T>createFlux(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate.ReactiveBucketCallback<T> callback) Create a reusable Flux for aReactiveGridFsTemplate.ReactiveBucketCallback.<T> Mono<T>createMono(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate.ReactiveBucketCallback<T> callback) Create a reusable Mono for aReactiveGridFsTemplate.ReactiveBucketCallback.Deletes all files matching the givenQuery.protected Mono<com.mongodb.reactivestreams.client.gridfs.GridFSBucket>Flux<com.mongodb.client.gridfs.model.GridFSFile>Returns aFluxemitting all files matching the given query.Mono<com.mongodb.client.gridfs.model.GridFSFile>Returns aMonoemitting the fristGridFSFilematching the given query orMono.empty()in case no file matches.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) getResource(com.mongodb.client.gridfs.model.GridFSFile file) getResource(String location) Returns aMonoemitting theReactiveGridFsResourcewith the given file name.getResources(String locationPattern) Returns aFluxemitting allReactiveGridFsResources matching the given file name pattern.Mono<org.bson.types.ObjectId>Stores the given content into a file with the given name and content type using the given metadata.<T> Mono<T>store(GridFsObject<T, Publisher<DataBuffer>> upload) protected org.bson.DocumenttoDocument(Object value) Convert a given value into aDocument.
-
Constructor Details
-
ReactiveGridFsTemplate
Creates a newReactiveGridFsTemplateusing the givenReactiveMongoDatabaseFactoryandMongoConverter.Note that the
GridFSBucketis obtained only once fromMongoDatabase. UseReactiveGridFsTemplate(MongoConverter, Mono, DataBufferFactory)if you want to use different buckets from the same Template instance.- 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.Note that the
GridFSBucketis obtained only once fromMongoDatabase. UseReactiveGridFsTemplate(MongoConverter, Mono, DataBufferFactory)if you want to use different buckets from the same Template instance.- Parameters:
dbFactory- must not be null.converter- must not be null.bucket- can be null.
-
ReactiveGridFsTemplate
public ReactiveGridFsTemplate(DataBufferFactory dataBufferFactory, ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, @Nullable String bucket) Creates a newReactiveGridFsTemplateusing the givenDataBufferFactory,ReactiveMongoDatabaseFactoryandMongoConverter.Note that the
GridFSBucketis obtained only once fromMongoDatabase. UseReactiveGridFsTemplate(MongoConverter, Mono, DataBufferFactory)if you want to use different buckets from the same Template instance.- Parameters:
dataBufferFactory- must not be null.dbFactory- must not be null.converter- must not be null.bucket- can be null.
-
ReactiveGridFsTemplate
public ReactiveGridFsTemplate(MongoConverter converter, Mono<com.mongodb.reactivestreams.client.gridfs.GridFSBucket> gridFSBucket, DataBufferFactory dataBufferFactory) Creates a newReactiveGridFsTemplateusing the givenMongoConverter,Monoemitting aReactiveMongoDatabaseFactoryandDataBufferFactory.- Parameters:
converter- must not be null.gridFSBucket- must not be null.dataBufferFactory- must not be null.- Since:
- 4.2
-
-
Method Details
-
store
public Mono<org.bson.types.ObjectId> store(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
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
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
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> 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> 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
-
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.
-