Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.iterator.next: Advance an iterator to the first or next field

Description

Advance a mongo.bson.iterator to the first or next field.

Usage

mongo.bson.iterator.next(iter)

Arguments

Value

(integer) The type of the next of the field pointed to by the iterator as indicated by the folllowing constants:

See Also

mongo.bson.iterator, mongo.bson.iterator.create, mongo.bson.find, mongo.bson.iterator.key, mongo.bson.iterator.type, mongo.bson.iterator.value, mongo.bson.

Examples

Run this code
buf <- mongo.bson.buffer.create()
# Append a string
mongo.bson.buffer.append(buf, "name", "Joe")
# Append a date/time
mongo.bson.buffer.append(buf, "created", Sys.time())
# Append a NULL
mongo.bson.buffer.append(buf, "cars", NULL)
b <- mongo.bson.from.buffer(buf)

iter <- mongo.bson.iterator.create(b)
# Advance to the "cars" field
while (mongo.bson.iterator.next(iter) != mongo.bson.null)
{
    # NOP
}
print(mongo.bson.iterator.value(iter))

# The above is given for illustrative purposes, but may be performed
# much easier by the following:
iter <- mongo.bson.find(b, "cars")
print(mongo.bson.iterator.value(iter))

# iterate through all values and print them with their keys (names)
iter <- mongo.bson.iterator.create(b)
while (mongo.bson.iterator.next(iter)) { # eoo at end stops loop
    print(mongo.bson.iterator.key(iter))
    print(mongo.bson.iterator.value(iter))
}

Run the code above in your browser using DataLab