rmongodb (version 1.8.0)

mongo.bson.from.list: Convert a list to a mongo.bson object

Description

Convert a list to a mongo.bson object.

Usage

mongo.bson.from.list(lst)

Arguments

lst
(list) The list to convert.

This must be a list, not a vector of atomic types; otherwise, an error is thrown; use as.list() as necessary.

Value

(mongo.bson) A mongo.bson object serialized from lst.

Details

This function permits the simple and convenient creation of a mongo.bson object. This bypasses the creation of a mongo.bson.buffer, appending fields one by one, and then turning the buffer into a mongo.bson object with mongo.bson.from.buffer().

Note that this function and mongo.bson.to.list() perform inverse conversions.

See Also

mongo.bson.to.list, mongo.bson, mongo.bson.destroy.

Examples

Run this code
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