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

Description Usage Arguments Details Value See Also Examples

View source: R/gridfs.R

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

1
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.

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.

Value

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

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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)
}

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.