Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.buffer.append.int: Append an integer field onto a mongo.bson.buffer

Description

Append an integer or vector of integers onto a mongo.bson.buffer.

Usage

mongo.bson.buffer.append.int(buf, name, value)

Arguments

buf
(mongo.bson.buffer) The buffer object to which to append.
name
(string) The name (key) of the field appended to the buffer.
value
(integer vector) The integer(s) to append to the buffer.

If value has a dims attribute of length > 1, any names or dimnames attribute is ignored and a nested array is appended. (Use mongo.bson.buffer.append.object() if you want to preserve dimnames).

If value has a names attribute, a subobject is appended and the subfields are given the indicated names.

Otherwise, if more than one element is present in value it must be a vector of integers and the integers are appended as a subarray.

In the last case, the single value must be coerible to an integer.

Value

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

See Also

mongo.bson, mongo.bson.buffer, mongo.bson.buffer.append.

Examples

Run this code
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.int(buf, "age", 23L)
b <- mongo.bson.from.buffer(buf)

# the above produces a BSON object of the form { "age" : 21 }

buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.int(buf, "ages", c(21L, 19L, 13L))
b <- mongo.bson.from.buffer(buf)

# the above produces a BSON object of the form { "ages" : [21, 19, 13] }

buf <- mongo.bson.buffer.create()
dim <- c(2L, 4L, 8L)
names(dim) <- c("width", "height", "length")
mongo.bson.buffer.append.int(buf, "board", dim)
b <- mongo.bson.from.buffer(buf)

# theabove produces a BSON object of the form:
# { "board" : { "width" : 2, "height" : 4, "length" : 8 } }

Run the code above in your browser using DataLab