Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.iterator.create: Create a mongo.bson.iterator object

Description

Create a mongo.bson.iterator object used to step through a given mongo.bson object one field at a time.

Usage

mongo.bson.iterator.create(b)

Arguments

b
(mongo.bson) The mongo.bson object through which to iterate.

b may also be a mongo.bson.iterator and is expected to point to a subobject or array. The iterator returned may be used to step through the subobject or array.

Value

(mongo.bson.iterator) An iterator initialized to 'before' the start of the given mongo.bson object. mongo.bson.iterator.next() should be used on the iterator first to step to the first field.

See Also

mongo.bson.iterator, mongo.bson.find, mongo.bson.iterator.next, 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)
while (mongo.bson.iterator.next(iter))
    if (mongo.bson.iterator.key(iter) == "created") {
        print(mongo.bson.iterator.value(iter))
        break
    }

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

Run the code above in your browser using DataLab