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