rmongodb (version 1.8.0)

mongo.gridfs.store: Store raw data as a file in a GridFS

Description

Store raw data as a file to a GridFS on a MongoDB server. This function stores the entire piece of data file on the server, breaking it up into 256K chunks as necessary.

Usage

mongo.gridfs.store(gridfs, raw, remotename, contenttype = "")

Arguments

gridfs
A (mongo.gridfs) object.
raw
(raw) The data to store on the server.
remotename
(string) The name the file will be known as within the GridFS.
contenttype
(string) Optional MIME content type.

Value

TRUE, if successful; FALSE, if an error occured during the operation.

Details

This function only handles the RAW type. Use writeBin() as necessary to pack your data appropriately for storage. See the examples and R's documentation on writeBin().

Use mongo.gridfile.writer when you need to buffer many writes to a GridFS file.

See Also

mongo.gridfs, mongo.gridfs.create, mongo.gridfs.remove.file.

Examples

Run this code
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    gridfs <- mongo.gridfs.create(mongo, "grid")
    # store 4 bytes
    mongo.gridfs.store(gridfs, charToRaw("test"), "test4.dat")

    # store string & LF plus 0-byte terminator
    buf <- writeBin("Test\n", as.raw(1))
    mongo.gridfs.store(gridfs, buf, "test6.dat")

    # store PI as a float
    buf <- writeBin(3.1415926, as.raw(1), size=4, endian="little")
    mongo.gridfs.store(gridfs, buf, "PI.dat")

    mongo.gridfs.destroy(gridfs)
}

Run the code above in your browser using DataLab