Learn R Programming

rmongodb (version 1.8.0)

mongo.gridfile.get.chunk: Get a chunk of a mongo.gridfile

Description

Get a chunk of a mongo.gridfile.

Usage

mongo.gridfile.get.chunk(gridfile, i)

Arguments

gridfile
A (mongo.gridfile) object.
i
(integer) The index of the chunk to fetch. This should be in the range 0 to mongo.gridfile.get.chunk.count(gridfile) - 1.

Value

  • (mongo.bson) the ith chunk of gridfile if successful; otherwise, NULL.

    The value returned is the ith document in the 'chunks' collection of the GridFS. The 'data' field of this document contains the actual data belonging to the chunk. See http://www.mongodb.org/display/DOCS/GridFS+Specification.

See Also

mongo.gridfs, mongo.gridfs.find, mongo.gridfile, mongo.gridfile.get.descriptor, mongo.gridfile.get.filename, mongo.gridfile.get.length, mongo.gridfile.get.chunk.size, mongo.gridfile.get.chunk.count, mongo.gridfile.get.content.type, mongo.gridfile.get.upload.date, mongo.gridfile.get.md5, mongo.gridfile.get.metadata, mongo.gridfile.get.chunks, mongo.gridfile.read, mongo.gridfile.seek, mongo.gridfile.pipe.

Examples

Run this code
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    gridfs <- mongo.gridfs.create(mongo, "grid")
    mongo.gridfs.store.file(gridfs, "tests/test.R", "test.R")

    gf <- mongo.gridfs.find(gridfs, "test.R")
    if( !is.null(gf)){
      chunk <- mongo.gridfile.get.chunk(gf, 0)
      iter <- mongo.bson.find(chunk, "data")


      f <- file("testChunk0.R", "wb")
      # write the binary (raw) data to a file
      writeBin(mongo.bson.iterator.value(iter), f)
      close(f)

      mongo.gridfile.destroy(gf)
    }
    mongo.gridfs.destroy(gridfs)
}

Run the code above in your browser using DataLab