GridFS

reactivemongo.api.gridfs.GridFS
See theGridFS companion object
sealed trait GridFS[P <: SerializationPack] extends UpsertedFactory[P] with QueryBuilderFactory[P]

A GridFS store.

Attributes

Companion:
object
Graph
Supertypes
trait QueryBuilderFactory[P]
class Object
trait Matchable
class Any
Self type

Members list

Concise view

Type members

Inherited classlikes

final class DeleteElement

Delete command element

Delete command element

Attributes

Inherited from:
DeleteCommand (hidden)
Graph
Supertypes
class Object
trait Matchable
class Any
sealed trait Hint

An index hint

An index hint

Attributes

Inherited from:
HintFactory (hidden)
Graph
Supertypes
class Object
trait Matchable
class Any
final class QueryBuilder

A builder that helps to make a fine-tuned query to MongoDB.

A builder that helps to make a fine-tuned query to MongoDB.

When the query is ready, you can call cursor to get a Cursor, or one if you want to retrieve just one document.

Attributes

batchSize

the upper limit on the number of documents to retrieve per batch (0 for unspecified)

collation

the optional collation to use for the find command (default: None) {@since MongoDB 3.4}

import scala.concurrent.{ ExecutionContext, Future }
import reactivemongo.api.bson.BSONDocument
import reactivemongo.api.bson.collection.BSONCollection
def firstFirst(coll: BSONCollection)(
 implicit ec: ExecutionContext): Future[Option[BSONDocument]] = {
 val queryBuilder = coll.find(BSONDocument.empty)
 queryBuilder.one[BSONDocument]
}
comment

the query comment

cursorOptions

the cursor options

explain

the explain flag

filter

the query filter

hint

the index to “hint” or force MongoDB to use when performing the query.

max

the optional exclusive upper bound for a specific index (default: None)

maxScan

this option specifies a maximum number of documents or index keys the query plan will scan.

maxTimeMs

the maximum execution time

min

the optional exclusive lower bound for a specific index (default: None)

projection

the projection specification

readConcern

the read concern {@since MongoDB 3.6}

readPreference

the query ReadPreference

returnKey

if this flag is true, returns only the index keys in the resulting documents

showRecordId

the flags to determines whether to return the record identifier for each document

singleBatch

the flag to determines whether to close the cursor after the first batch (default: false)

skip

the number of documents to skip.

snapshot

the snapshot flag

sort

the optional sort specification

Inherited from:
QueryBuilderFactory
Graph
Supertypes
class Object
trait Matchable
class Any
final class UpdateElement(val q: Document, val u: Either[Document, Seq[Document]], val upsert: Boolean, val multi: Boolean, val collation: Option[Collation], val arrayFilters: Seq[Document])

Attributes

arrayFilters

an array of filter documents that determines which array elements to modify for an update operation on an array field

collation

the collation to use for the operation

multi

if true updates all the matching documents

q

the query that matches the documents to update

u

the modifications to apply

upsert

if true perform an insert if no documents match the query

Inherited from:
UpdateCommand (hidden)
Graph
Supertypes
class Object
trait Matchable
class Any
final class UpdateWriteResult extends WriteResult

Result for the update operations.

Result for the update operations.

Attributes

n

the number of documents selected for update

nModified

the number of updated documents

ok

the update status

upserted

the upserted documents

Inherited from:
UpdateWriteResultFactory (hidden)
Graph
Supertypes
class Object
trait Matchable
class Any
final class Upserted

An upserted element

An upserted element

Attributes

Inherited from:
UpsertedFactory
Graph
Supertypes
class Object
trait Matchable
class Any
object Upserted

Attributes

Inherited from:
UpsertedFactory
Graph
Supertypes
class Object
trait Matchable
class Any

Types

type FileToSave[Id <: Value] = FileToSave[Id, Document]
type ReadFile[+Id <: Value] = ReadFile[Id, Document]

Inherited types

final type DeleteResult = DefaultWriteResult

Result for a delete command

Result for a delete command

Attributes

Inherited from:
DeleteCommand (hidden)

Value members

Concrete methods

def chunks(file: ReadFile[Value], readPreference: ReadPreference)(implicit cp: CursorProducer[Array[Byte]]): ProducedCursor

Returns a cursor for the chunks of the specified file. The cursor walks the chunks orderly.

Returns a cursor for the chunks of the specified file. The cursor walks the chunks orderly.

Attributes

file

the file to be read

Creates the needed indexes on the GridFS collections (chunks and files).

Creates the needed indexes on the GridFS collections (chunks and files).

Please note that you should really consider reading http://www.mongodb.org/display/DOCS/Indexes before doing this, especially in production.

Attributes

Returns:

A future containing true if the index was created, false if it already exists.

Returns whether the data related to this GridFS instance exists on the database.

Returns whether the data related to this GridFS instance exists on the database.

Attributes

def fileToSave(filename: Option[String], contentType: Option[String], uploadDate: Option[Long], metadata: Document): FileToSave[Value]

Prepare the information to save a file. The unique ID is automatically generated.

Prepare the information to save a file. The unique ID is automatically generated.

Attributes

def fileToSave[Id <: Value](filename: Option[String], contentType: Option[String], uploadDate: Option[Long], metadata: Document, id: Id): FileToSave[Id]

Prepare the information to save a file.

Prepare the information to save a file.

Attributes

def find[S, Id <: Value](selector: S)(implicit w: Writer[S], r: FileReader[Id], cp: CursorProducer[ReadFile[Id]]): ProducedCursor

Finds the files matching the given selector.

Finds the files matching the given selector.

Attributes

Id

the type of the file ID to be read

import scala.concurrent.ExecutionContext
import reactivemongo.api.gridfs.GridFS
import reactivemongo.api.bson.{ BSONDocument, BSONValue }
import reactivemongo.api.bson.collection.{ BSONSerializationPack => Pack }
def foo(gfs: GridFS[Pack.type], n: String)(implicit ec: ExecutionContext) =
 gfs.find[BSONDocument, BSONValue](
   BSONDocument("filename" -> n)).headOption
S

The type of the selector document. An implicit Writer[S] must be in the scope.

r

fileReader a file reader automatically resolved if Id is a valid value

selector

the query to find the files

def find(selector: Document)(implicit cp: CursorProducer[ReadFile[Value]]): ProducedCursor

Finds the files matching the given selector.

Finds the files matching the given selector.

Attributes

r

fileReader a file reader automatically resolved if Id is a valid value

import scala.concurrent.ExecutionContext
import reactivemongo.api.gridfs.GridFS
import reactivemongo.api.bson.BSONDocument
import reactivemongo.api.bson.collection.{ BSONSerializationPack => Pack }
def foo(gfs: GridFS[Pack.type], n: String)(implicit ec: ExecutionContext) =
 gfs.find(BSONDocument("filename" -> n)).headOption
selector

the query to find the files

def readToOutputStream[Id <: Value](file: ReadFile[Id], out: OutputStream, readPreference: ReadPreference)(implicit ec: ExecutionContext): Future[Unit]

Reads the given file and writes its contents to the given OutputStream.

Reads the given file and writes its contents to the given OutputStream.

Attributes

file

the file to be read

def remove[Id <: Value](id: Id)(implicit ec: ExecutionContext): Future[WriteResult]

Removes a file from this store. Note that if the file does not actually exist, the returned future will not be hold an error.

Removes a file from this store. Note that if the file does not actually exist, the returned future will not be hold an error.

Attributes

id

the file id to remove from this store

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns:

a string representation of the object.

Definition Classes
Any
def update[Id <: Value](id: Id, metadata: Document)(implicit ec: ExecutionContext): Future[WriteResult]

Updates the metadata document for the specified file.

Updates the metadata document for the specified file.

Attributes

id

the id of the file to be updated

metadata

the file new metadata

def writeFromInputStream[Id <: Value](file: FileToSave[Id], input: InputStream, chunkSize: Int)(implicit ec: ExecutionContext): Future[ReadFile[Id]]

Writes the data provided by the given InputStream to the given file.

Writes the data provided by the given InputStream to the given file.

Attributes

Inherited methods

protected def concat[T](a1: Array[T], a2: Array[T])(implicit m: ClassTag[T]): Array[T]

Attributes

Inherited from:
GridFSCompat (hidden)
final protected def deleteWriter(session: Option[Session]): Writer[DeleteCmd]

Attributes

Inherited from:
DeleteCommand (hidden)
def hint(specification: Document): Hint

Returns a hint for the given index specification document.

Returns a hint for the given index specification document.

Attributes

specification

the index specification document

Inherited from:
HintFactory (hidden)
def hint(name: String): Hint

Returns a hint for the given index name.

Returns a hint for the given index name.

Attributes

name

the index name

Inherited from:
HintFactory (hidden)

Inherited fields

val pack: P

The serialization pack (BSON by default).

The serialization pack (BSON by default).

Used to resolve the types of values (by default BSONValue, BSONDocument, ...), and the related typeclasses (e.g. BSONDocumentReader ...).

Attributes

Inherited from:
PackSupport (hidden)

Implicits

Inherited implicits

final implicit lazy protected val resultReader: Reader[DefaultWriteResult]

Attributes

Inherited from:
CommandCodecsWithPack (hidden)
final implicit protected def updateReader: Reader[UpdateWriteResult]

Attributes

Inherited from:
UpdateCommand (hidden)