lst <- list(name="John", age=32)
b <- mongo.bson.from.list(lst)
# the above produces a BSON object of the form:
# { "name" : "John", "age" : 32.0 }
# Convert a vector of an atomic type to a list and
# then to a mongo.bson object
v <- c(president="Jefferson", vice="Burr")
b <- mongo.bson.from.list(as.list(v))
# the above produces a BSON object of the form:
# { "president" : "Jefferson", "vice" : "Burr" }
# Let's try to construct bson with array.
# This one
mongo.bson.from.list(list(fruits = list('apple', 'banana', 'orange')))
# will produce a BSON object of the form:
# {"fruits" : ["apple", "banana", "orange"]}
Run the code above in your browser using DataLab