rmongodb (version 1.8.0)

mongo.gridfs.find: Find a GridFS file

Description

Find a GridFS file and return a mongo.gridfile object used for further operations on it

Usage

mongo.gridfs.find(gridfs, query)

Arguments

gridfs
A (mongo.gridfs) object.
query
(string) The name of the GridFS file to locate.

This parameter may also be a mongo.bson query object and is used to search the GridFS "files" collection documents for matches. Alternately, query may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Value

NULL, if not found; otherwise, a mongo.gridfile object corresponding to the found GridFS file.

See Also

mongo.gridfile, mongo.gridfile.get.filename, mongo.gridfs.

Examples

Run this code
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    gridfs <- mongo.gridfs.create(mongo, "grid")

    gf <- mongo.gridfs.find(gridfs, "test.dat")
    print(mongo.gridfile.get.length(gf))

    # find a GridFS file uploaded midnight July 4, 2008
    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "uploadDate",
        strptime("07-04-2008", "%m-%d-%Y"))
    query <- mongo.bson.from.buffer(buf)
    gf <- mongo.gridfs.find(gridfs, query)

    if (!is.null(gf))
        print(mongo.gridfile.get.filename(gf))

    mongo.gridfs.destroy(gridfs)
}

Run the code above in your browser using DataLab