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
ConstructorDescriptionReactiveGridFsTemplate
(DataBufferFactory dataBufferFactory, ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, String bucket) Creates a newReactiveGridFsTemplate
using the givenDataBufferFactory
,ReactiveMongoDatabaseFactory
andMongoConverter
.ReactiveGridFsTemplate
(MongoConverter converter, reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.gridfs.GridFSBucket> gridFSBucket, DataBufferFactory dataBufferFactory) Creates a newReactiveGridFsTemplate
using the givenMongoConverter
,Mono
emitting aReactiveMongoDatabaseFactory
andDataBufferFactory
.ReactiveGridFsTemplate
(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter) Creates a newReactiveGridFsTemplate
using the givenReactiveMongoDatabaseFactory
andMongoConverter
.ReactiveGridFsTemplate
(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, String bucket) Creates a newReactiveGridFsTemplate
using the givenReactiveMongoDatabaseFactory
andMongoConverter
. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.mongodb.client.gridfs.model.GridFSUploadOptions
computeUploadOptionsFor
(String contentType, org.bson.Document metadata) Compute theGridFSUploadOptions
to 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 aFlux
emitting all files matching the given query.reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile>
Returns aMono
emitting the fristGridFSFile
matching the given query orMono.empty()
in case no file matches.reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile>
Returns aMono
emitting a singleGridFSFile
matching the given query orMono.empty()
in case no file matches.protected org.bson.Document
getMappedQuery
(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 aMono
emitting theReactiveGridFsResource
with the given file name.reactor.core.publisher.Flux<ReactiveGridFsResource>
getResources
(String locationPattern) Returns aFlux
emitting allReactiveGridFsResource
s 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.Document
toDocument
(Object value) Convert a given value into aDocument
.
-
Constructor Details
-
ReactiveGridFsTemplate
Creates a newReactiveGridFsTemplate
using the givenReactiveMongoDatabaseFactory
andMongoConverter
.Note that the
GridFSBucket
is 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 newReactiveGridFsTemplate
using the givenReactiveMongoDatabaseFactory
andMongoConverter
.Note that the
GridFSBucket
is 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 newReactiveGridFsTemplate
using the givenDataBufferFactory
,ReactiveMongoDatabaseFactory
andMongoConverter
.Note that the
GridFSBucket
is 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, reactor.core.publisher.Mono<com.mongodb.reactivestreams.client.gridfs.GridFSBucket> gridFSBucket, DataBufferFactory dataBufferFactory) Creates a newReactiveGridFsTemplate
using the givenMongoConverter
,Mono
emitting aReactiveMongoDatabaseFactory
andDataBufferFactory
.- Parameters:
converter
- must not be null.gridFSBucket
- must not be null.dataBufferFactory
- must not be null.- Since:
- 4.2
-
-
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:ReactiveGridFsOperations
Stores 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:
store
in interfaceReactiveGridFsOperations
- Parameters:
content
- must not be null.filename
- must not be null or empty.contentType
- can be null.metadata
- can be null- Returns:
- a
Mono
emitting theObjectId
of theGridFSFile
just created.
-
store
public <T> reactor.core.publisher.Mono<T> store(GridFsObject<T, org.reactivestreams.Publisher<DataBuffer>> upload) Description copied from interface:ReactiveGridFsOperations
Stores 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:
store
in interfaceReactiveGridFsOperations
- Type Parameters:
T
- id type of the underlyingGridFSFile
- Parameters:
upload
- theGridFsObject
(most likely aGridFsUpload
) to be stored.- Returns:
Mono
emitting the id of the stored file which is either an auto created value orGridFsObject.getFileId()
.
-
find
Description copied from interface:ReactiveGridFsOperations
Returns aFlux
emitting all files matching the given query.
NOTE: CurrentlySort
criteria defined at theQuery
will not be regarded as MongoDB does not support ordering for GridFS file access.- Specified by:
find
in interfaceReactiveGridFsOperations
- Parameters:
query
- must not be null.- Returns:
Flux.empty()
if no mach found.- See Also:
-
findOne
Description copied from interface:ReactiveGridFsOperations
Returns aMono
emitting a singleGridFSFile
matching the given query orMono.empty()
in case no file matches.
NOTE: If more than one file matches the given query the resultingMono
emits an error. If you want to obtain the first found file useReactiveGridFsOperations.findFirst(Query)
.- Specified by:
findOne
in 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:ReactiveGridFsOperations
Returns aMono
emitting the fristGridFSFile
matching the given query orMono.empty()
in case no file matches.- Specified by:
findFirst
in interfaceReactiveGridFsOperations
- Parameters:
query
- must not be null.- Returns:
Mono.empty()
if not match found.
-
delete
Description copied from interface:ReactiveGridFsOperations
Deletes all files matching the givenQuery
.- Specified by:
delete
in interfaceReactiveGridFsOperations
- Parameters:
query
- must not be null.- Returns:
- a
Mono
signalling operation completion.
-
getResource
Description copied from interface:ReactiveGridFsOperations
Returns aMono
emitting theReactiveGridFsResource
with the given file name.- Specified by:
getResource
in 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:
getResource
in interfaceReactiveGridFsOperations
- Parameters:
file
- must not be null.- Returns:
Mono.empty()
if no match found.
-
getResources
Description copied from interface:ReactiveGridFsOperations
Returns aFlux
emitting allReactiveGridFsResource
s matching the given file name pattern.- Specified by:
getResources
in 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 newFlux
or to reuse theFlux
.- Parameters:
callback
- must not be null- Returns:
- a
Mono
wrapping 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 newFlux
or to reuse theFlux
.- Parameters:
callback
- must not be null- Returns:
- a
Flux
wrapping 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 aQueryMapper
to apply type conversion.- Returns:
- never null.
-
computeUploadOptionsFor
protected com.mongodb.client.gridfs.model.GridFSUploadOptions computeUploadOptionsFor(@Nullable String contentType, @Nullable org.bson.Document metadata) Compute theGridFSUploadOptions
to 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
Document
if the source value is null.
-