Learn R Programming

rmongodb (version 1.8.0)

mongo.cursor.destroy: Release resources attached to a cursor

Description

mongo.cursor.destroy(cursor) is used to release resources attached to a cursor on both the client and server.

Usage

mongo.cursor.destroy(cursor)

Arguments

cursor
(mongo.cursor) A mongo.cursor object returned from mongo.find().

Value

TRUE if successful; otherwise, FALSE (when an error occurs during sending the Kill Cursor operation to the server). in either case, the cursor should not be used for further operations.

Details

Note that mongo.cursor.destroy(cursor) may be called before all records of a result set are iterated through (for example, if a desired record is located in the result set).

Although the 'destroy' functions in this package are called automatically by garbage collection, this one in particular should be called as soon as feasible when finished with the cursor so that server resources are freed.

See Also

mongo.find, mongo.cursor, mongo.cursor.next, mongo.cursor.value.

Examples

Run this code
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "city", "St. Louis")
    query <- mongo.bson.from.buffer(buf)

    # Find the first 1000 records in collection people
    # of database test where city == "St. Louis"
    cursor <- mongo.find(mongo, "test.people", query, limit=1000L)
    # Step though the matching records and display them
    while (mongo.cursor.next(cursor))
        print(mongo.cursor.destroy(cursor))
    mongo.cursor.destroy(cursor)
}

Run the code above in your browser using DataLab