Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.buffer.start.array: Start an array within a mongo.bson.buffer

Description

Call this function to start an array within a mongo.bson.buffer. mongo.bson.buffer.finish.object() must be called when finished appending the elements of the array.

Usage

mongo.bson.buffer.start.array(buf, name)

Arguments

buf
(mongo.bson.buffer) The buffer object to which to append.
name
(string) The name (key) of the array to be appended to the buffer.

Value

TRUE if successful; otherwise, FALSE if an error occured appending the data.

Details

(mongo.bson.buffer.start.object(), mongo.bson.buffer.start.array()) and mongo.bson.buffer.finsih.object() may be called in a stackwise (LIFO) order to further nest arrays and documents.

The names of the elements appended should properly be given sequentially numbered strings.

Note that arrays will be automatically appended by the 'append' functions when appending vectors (containing more than one element) of atomic types.

See Also

mongo.bson, mongo.bson.buffer, mongo.bson.buffer.finish.object, mongo.bson.buffer.start.array, mongo.bson.buffer.append.

Examples

Run this code
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.start.array(buf, "Fibonacci")
x <- 0
mongo.bson.buffer.append.int(buf, "0", x)
y <- 1
mongo.bson.buffer.append.int(buf, "1", y)
for (i in 2:8) {
    z <- x + y
    mongo.bson.buffer.append.int(buf, as.character(i), z)
    x <- y
    y <- z
}
mongo.bson.buffer.finish.object(buf)
b <- mongo.bson.from.buffer(buf)

# the above produces a BSON object of the form:
# { "Fibonacci" : [ 0, 1, 1, 2, 3, 5, 8, 13, 21 ] }

Run the code above in your browser using DataLab