mongo.gridfile.get.chunks: Get a cursor for a range of chunks in a mongo.gridfile

Description Usage Arguments Value See Also Examples

View source: R/gridfs.R

Description

Get a mongo.cursor for a range of chunks in a mongo.gridfile.

Usage

1
mongo.gridfile.get.chunks(gridfile, start, count)

Arguments

gridfile

A (mongo.gridfile) object.

start

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

count

(integer) The number of chunks to fetch.

Value

(mongo.cursor) A cursor to be used to step through the requested chunks.

The values returned by mongo.cursor.value() will be consecutive documents in the 'chunks' collection of the GridFS. The 'data' field of these documents 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.chunk,
mongo.gridfile.read,
mongo.gridfile.seek,
mongo.gridfile.pipe.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)){
      cursor <- mongo.gridfile.get.chunks(gf, 1, 2)

      f <- file("rmongodb.pdf.chunks12", "wb")
      while (mongo.cursor.next(cursor)) {
          chunk <- mongo.cursor.value(cursor)
          iter <- mongo.bson.find(chunk, "data")

          # write the binary (raw) data to the file
          writeBin(mongo.bson.iterator.value(iter), f)
      }
      close(f)
      mongo.gridfile.destroy(gf)
    }
    mongo.gridfs.destroy(gridfs)
}

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