buf <- mongo.bson.buffer.create()
# Append a string
mongo.bson.buffer.append(buf, "name", "Joe")
# Append a date/time
mongo.bson.buffer.append(buf, "created", Sys.time())
# Append a NULL
mongo.bson.buffer.append(buf, "cars", NULL)
b <- mongo.bson.from.buffer(buf)
# Display the date appended above
print(mongo.bson.value(b, "created"))
b <- mongo.bson.from.list(list(name="John", age=32L,
address=list(street="Vine", city="Denver", state="CO")))
print(mongo.bson.value(b, "age")) # print 32
print(mongo.bson.value(b, "address.state")) # print CO
x <- c(1,1,2,3,5)
b <- mongo.bson.from.list(list(fib=x)) # BSON arrays are 0-based
print(mongo.bson.value(b, "fib.4")) # print 5
Run the code above in your browser using DataLab