Class ReactiveGridFsTemplate

java.lang.Object
org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate
All Implemented Interfaces:
ReactiveGridFsOperations

public class ReactiveGridFsTemplate extends Object implements 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 Details

  • 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 interface ReactiveGridFsOperations
      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 the ObjectId of the GridFSFile 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 given GridFsObject, likely a GridFsUpload, into into a file with given name. If the GridFsObject.getFileId() is set, the file will be stored with that id, otherwise the server auto creates a new id.
      Specified by:
      store in interface ReactiveGridFsOperations
      Type Parameters:
      T - id type of the underlying GridFSFile
      Parameters:
      upload - the GridFsObject (most likely a GridFsUpload) to be stored.
      Returns:
      Mono emitting the id of the stored file which is either an auto created value or GridFsObject.getFileId().
    • find

      public reactor.core.publisher.Flux<com.mongodb.client.gridfs.model.GridFSFile> find(Query query)
      Description copied from interface: ReactiveGridFsOperations
      Returns a Flux emitting all files matching the given query.
      Note: Currently Sort criteria defined at the Query will not be regarded as MongoDB does not support ordering for GridFS file access.
      Specified by:
      find in interface ReactiveGridFsOperations
      Parameters:
      query - must not be null.
      Returns:
      Flux.empty() if no mach found.
      See Also:
    • findOne

      public reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile> findOne(Query query)
      Description copied from interface: ReactiveGridFsOperations
      Returns a Mono emitting a single GridFSFile matching the given query or Mono.empty() in case no file matches.
      NOTE If more than one file matches the given query the resulting Mono emits an error. If you want to obtain the first found file use ReactiveGridFsOperations.findFirst(Query).
      Specified by:
      findOne in interface ReactiveGridFsOperations
      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 a Mono emitting the frist GridFSFile matching the given query or Mono.empty() in case no file matches.
      Specified by:
      findFirst in interface ReactiveGridFsOperations
      Parameters:
      query - must not be null.
      Returns:
      Mono.empty() if not match found.
    • delete

      public reactor.core.publisher.Mono<Void> delete(Query query)
      Description copied from interface: ReactiveGridFsOperations
      Deletes all files matching the given Query.
      Specified by:
      delete in interface ReactiveGridFsOperations
      Parameters:
      query - must not be null.
      Returns:
      a Mono signalling operation completion.
    • getResource

      public reactor.core.publisher.Mono<ReactiveGridFsResource> getResource(String location)
      Description copied from interface: ReactiveGridFsOperations
      Returns a Mono emitting the ReactiveGridFsResource with the given file name.
      Specified by:
      getResource in interface ReactiveGridFsOperations
      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
      Returns a Mono emitting the ReactiveGridFsResource for a GridFSFile.
      Specified by:
      getResource in interface ReactiveGridFsOperations
      Parameters:
      file - must not be null.
      Returns:
      Mono.empty() if no match found.
    • getResources

      public reactor.core.publisher.Flux<ReactiveGridFsResource> getResources(String locationPattern)
      Description copied from interface: ReactiveGridFsOperations
      Returns a Flux emitting all ReactiveGridFsResources matching the given file name pattern.
      Specified by:
      getResources in interface ReactiveGridFsOperations
      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 a ReactiveGridFsTemplate.ReactiveBucketCallback. It's up to the developer to choose to obtain a new Flux or to reuse the Flux.
      Parameters:
      callback - must not be null
      Returns:
      a Mono wrapping the ReactiveGridFsTemplate.ReactiveBucketCallback.
    • createFlux

      public <T> reactor.core.publisher.Flux<T> createFlux(org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate.ReactiveBucketCallback<T> callback)
      Create a reusable Flux for a ReactiveGridFsTemplate.ReactiveBucketCallback. It's up to the developer to choose to obtain a new Flux or to reuse the Flux.
      Parameters:
      callback - must not be null
      Returns:
      a Flux wrapping the ReactiveGridFsTemplate.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 a QueryMapper 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 the GridFSUploadOptions to be used from the given contentType and metadata Document.
      Parameters:
      contentType - can be null.
      metadata - can be null
      Returns:
      never null.
    • toDocument

      protected org.bson.Document toDocument(@Nullable Object value)
      Convert a given value into a Document.
      Parameters:
      value - can be null.
      Returns:
      an empty Document if the source value is null.