Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.buffer.append: Append a name/value pair into a mongo.bson.buffer

Description

Append a name/value pair into a mongo.bson.buffer.

Usage

mongo.bson.buffer.append(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
The value of the field.

Value

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

Details

This function is a generic version of many 'append' functions. It will detect the type of the value parameter and perform the same action as the specific functions. These functions are:

mongo.bson.buffer.append.long() is missing from the above list since R has no 64-bit long integer type. If you wish a value to be stored in the BSON data as a long you must explicity call that function.

All of the above functions will lose the attributes of the object other than "names". When vectors of length > 1 are appended, "names" are preserved. mongo.bson.buffer.append.object() gets around this shortcoming and allows most R objects to be stored in a database without loss of attributes.

See Also

mongo.bson, mongo.bson.buffer.

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)

Run the code above in your browser using DataLab