buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.double(buf, "YearSeconds",
365.24219 * 24 * 60 * 60)
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "YearSeconds" : 31556925.2 }
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.double(buf, "dbls",
c(1.7, 87654321.123, 12345678.321))
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "dbls" : [1.7, 87654321.123, 12345678.321] }
buf <- mongo.bson.buffer.create()
fractions <- c(0.5, 0.25, 0.333333)
names(fractions) <- c("Half", "Quarter", "Third")
mongo.bson.buffer.append.double(buf, "Fractions", fractions)
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "Fractions" : { "Half" : 0.5,
# "Quarter" : 0.25,
# "Third" : 0.333333 } }
Run the code above in your browser using DataLab