Writing files to filesystem

Writing files to filesystem

Mongo Streams provides syntax to build sink that writes to mongo filesystem. Syntax can define to what file data has to be
written, what can be chunk-size and what metadata should be associated with file.

File syntax

File syntax creates file reference that indicates where the file has to be saved and with which data.
Following syntax is available:

  • File named foo file("foo")
  • File named foo with supplied Id file("foo", id = new ObjectId)
  • File named foo with MIME content type file("foo", contentType = Some("text/plain; charset=UTF-8"))
  • File named foo with supplied size of chunk file("foo", chunkSize = 1024)
  • File named foo with supplied metadata file("foo", meta = Some(BSONObject("user" -> "luke")))

    Writing single file

Writing single file is easy simple syntax. Writing operation does not modify supplied Bytes object, therefore the
Bytes object may be recycled for better efficiency

 source10k to (filesystem(fileDb) using (write file ("foo.txt")))

Total for specification FSWriteSpec
Finished in1 second, 325 ms
Results1 example, 0 failure, 0 error