mongo.cursor: The mongo.cursor class

Description Details See Also Examples

Description

Objects of class "mongo.cursor" are returned from mongo.find() and used to iterate over the records matching the query.

Details

mongo.cursor.next(cursor) is used to step to the first or next record.

mongo.cursor.value(cursor) returns a mongo.bson object representing the current record.

mongo.cursor.destroy(cursor) releases the resources attached to the cursor.

mongo.cursor objects have "mongo.cursor" as their class and contain an externally managed pointer to the actual cursor data. This pointer is stored in the "mongo.cursor" attribute of the object.

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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.value(cursor))
    mongo.cursor.destroy(cursor)
}

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