Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.buffer.append.string: Append a string field onto a mongo.bson.buffer

Description

Append an string or vector of strings onto a mongo.bson.buffer.

Usage

mongo.bson.buffer.append.string(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
(string vector) The strings(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, the strings are appended as a subarray.

In the last case, a single string is appended as the value of the field.

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.string(buf, "name", "Joe")
b <- mongo.bson.from.buffer(buf)

# The above produces a BSON object of the form { "name" : "Joe" }

buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.string(buf, "names", c("Fred", "Jeff", "John"))
b <- mongo.bson.from.buffer(buf)

# The above produces a BSON object of the form:
# { "names" : ["Fred", "Jeff", "John"] }

buf <- mongo.bson.buffer.create()
staff <- c("Mark", "Jennifer", "Robert")
names(staff) <- c("Chairman", "President", "Secretary")
mongo.bson.buffer.append.string(buf, "board", staff)
b <- mongo.bson.from.buffer(buf)

# The above produces a BSON object of the form:
# { "board" : { "Chairman"  : "Mark",
#               "President" : "Jennifer",
#               "Secretary" : "Robert" } }

Run the code above in your browser using DataLab