knitr::opts_chunk$set(echo = TRUE)

GridFS API in mongolite will be a new top level object class, consistent with the current API to instantiate regular mongodb collection objects.

fs <- mongolite::gridfs(db = "test", url = "mongodb://localhost")

The initial API will focus on basic read/write/delete operations.

Error Handling

All methods will automatically translate mongoc exceptions into R errors.

Listing Files

Returns a data frame with files and fixed meta data (size, date, content-type, etc).

list <- fs$list(filter = '{}', options = '{}')

References:

Reading Files

A file can be read either into a buffer, or streamed to a file or connection. The default behavior is to read the entire file and return the data in a raw data vector:

buf <- fs$read(name = "myfile.bin")

Alternatively the user can supply an R connection object that we can use to stream data to e.g. a file or network socket.

fs$read(name = "myfile.bin", con = connection)

The latter will be a memory efficient way to incrementally read from the GridFS and write out the data. It is similar to the export() method for regular mongo collection objects.

References:

Writing Files

Analogous to reading, a write operation can either write a raw data vector from memory or stream data from a local file or connection object.

fs$write(name = "myfile.bin", data = buffer)

When the data argument is an R connection object, it will incrementally read from the connection and upload to GridFS.

fs$write(name = "myfile.bin", data = connection)

References:

Removing Files

Removes a single file from the GridFS collection:

fs$remove(name = "myfile.bin")

Here the name argument can be vectorized in standard R fashion such that multiple files can be removed with a single call.

References:

Drop GridFS

Requests that an entire GridFS be dropped, including all files associated with it.

fs$drop()

References:



jeroenooms/mongolite documentation built on Jan. 12, 2024, 10:11 p.m.