Learn R Programming

rmongodb (version 1.8.0)

mongo.cursor.to.list: Convert Mongo Cursor Object to List so that each element of resulting list represents document in source collection.

Description

Converts a mongo cursor object to a list by interating over all cursor objects and combining them. It doesn't make any data coercion!, just one-to-one mapping with documents in source collection.

Usage

mongo.cursor.to.list(cursor, keep.ordering = TRUE)

Arguments

cursor
(mongo.cursor) A mongo.cursor object returned from mongo.find().
keep.ordering
should the records be returned at the same order as fetched from cursor (if sorting was specified in query)? For speed try to set this parameter to FALSE. This will prevent sorting after fetching from cursor.

Value

An R list object.

Details

Since rmongodb 1.8.0 function uses environments to avoid extra copying, so now it is much faster.

See Also

mongo.find

Examples

Run this code
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "age", 22L)
    query <- mongo.bson.from.buffer(buf)

    # Find the first 100 records
    #    in collection people of database test where age == 22
    cursor <- mongo.find(mongo, "test.people", query, limit=100L)

    res <- mongo.cursor.to.list(cursor)

}

Run the code above in your browser using DataLab