buf <- mongo.bson.buffer.create()
bin <- raw(3)
for (i in 0:2)
bin[i] <- as.raw(i * 3)
mongo.bson.buffer.append.raw(buf, "bin1", bin)
# Note that mongo.bson.buffer.append()
# will detect whether the value parameter
# is a raw object and append the appropriate value.
mongo.bson.buffer.append(buf, "bin2", bin) # gives same result
Run the code above in your browser using DataLab