mongo.bson.iterator.value: Return the value of the field pointed to by an iterator

Description Usage Arguments Value See Also Examples

View source: R/bson.R

Description

Return the value of the field pointed to by a mongo.bson.iterator.

Usage

1

Arguments

iter

A mongo.bson.iterator.

Value

The value of the field pointed to by iter.

This function returns an appropriate R object depending on the type of the field pointed to by the iterator. This mapping to values is as follows:

mongo.bson.eoo 0L
mongo.bson.double A double
mongo.bson.string A string
mongo.bson.object (See below).
mongo.bson.array (See below).
mongo.bson.binary A raw vector. (See below).
mongo.bson.undefined A mongo.undefined object
mongo.bson.oid A mongo.oid object
mongo.bson.bool A logical
mongo.bson.date A "POSIXct" class object
mongo.bson.null NULL
mongo.bson.regex A mongo.regex object
mongo.bson.dbref Error! (deprecated -- see link)
mongo.bson.code A mongo.code object
mongo.bson.symbol A mongo.symbol object
mongo.bson.code.w.scope A mongo.code.w.scope object
mongo.bson.int An integer
mongo.bson.timestamp A mongo.timestamp object
mongo.bson.long A double

Special handling:

mongo.bson.object: If the object is recognized as a complex value (of the form "r" : double, "i" : double ), a complex value is returned. If the special wrapper as output by
mongo.bson.buffer.append.object() is detected, an appropriately attributed R object is returned; otherwise, a list is returned containing the subfields.

mongo.bson.array: If all fields of the array are of the same atomic type, a vector of that type is returned. (Multidimensinal arrays are detected and the dims attribute will be set accordingly. Arrays of complex values are also detected as above). Otherwise, a list is returned containing the subfields.

mongo.bson.binary: If non-zero, the subtype of the binary data is stored in the attribute "subtype". See mongo.bson.buffer.append.raw().

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)

# 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))
}

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