buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.long(buf, "YearSeconds",
365.24219 * 24 * 60 * 60)
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "YearSeconds" : 31556925 }
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.long(buf, "longs",
c(1, 9087654321, 1234567809))
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "longs" : [1, 9087654321, 1234567809] }
buf <- mongo.bson.buffer.create()
distances <- c(473, 133871000, 188178313)
names(distances) <- c("Sol", "Proxima Centari", "Bernard's Star")
mongo.bson.buffer.append.long(buf, "Stars", distances)
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "Stars" : { "Sol" : 474,
# "Proxima Centari" : 133871000,
# "Bernard's Star" : 188178313 } }
Run the code above in your browser using DataLab