Listing files in filesystem

Listing files in filesystem

Basic lists

To list files named with given name use named syntax:

 list named ("file1")

Concrete files can be queried by specifying their id :

 list withId (fileId)

Complex queries

Each mongodb file stores metadata that can content basically everything as normal bson document. However there
are some specific properties that are included in this document:

  • _id contains unique identification of file that is either supplied when writing to document or generated by driver
  • filename filename of the document, this may not be unique,
  • contentType MIME type of the file, may be null
  • length size of the file in bytes
  • chunkSize size of the file chunk. File is chunked in database and then reassembled on read
  • uploadDate date when the file was uploaded to the db
  • aliases aliases of the file (array of strings)
  • md5 MD5 hash of file content
  • metadata Object holding metadata for the file collection

Metadata are thus residing in metadata key, and anything that has to be queried in metadata must be prefixed by metadata.
Following are the examples of complex file queries :

  • Where file name contains character a:
 list files ("filename" regex ".*a.*")
  • Where file MIME type is text/plain; charset=UTF-8 :
 list files ("contentType" === "text/plain; charset=UTF-8")
  • Where metadata key user is luke:
 list files ("metadata.user" === "luke")

Combining result of listing the files

The individual listing of the files can be combined together to make different queries, even from different filesystems
via append (or ++) combinator.

val allFiles = (list named ("alpha")) ++
        (list named ("beta")) ++
        (list files ("filename" regex "g.*"))
 filesTest.listCompose
 todo TODO

Total for specification FSListSpec
Finished in5 seconds, 813 ms
Results7 examples, 0 failure, 0 error, 1 pending