Learn R Programming

rmongodb (version 1.8.0)

mongo.bson.to.list: Convert a mongo.bson object to an R list object.

Description

Convert a mongo.bson object to an R list object.

Usage

mongo.bson.to.list(b, simplify = TRUE)

Arguments

b
(mongo.bson) The mongo.bson object to convert.
simplify
logical (default: TRUE); should the bson arrays be simplified to a vectors if possible? If types of values in bson array are heterogeneous or non-primitive, array will be converted into list.

Value

an R object of the type list

See Also

mongo.bson.from.list, mongo.bson.to.Robject, mongo.bson.

Examples

Run this code
# arrays will be converted into unnamed lists without any symplifying:
l <- list(storageArray = list('value_1', 'value_2'))
# Here we construct bson of form {'storageArray':['value_1''value_2']}
b <- mongo.bson.from.list(l)
# simplify
print(mongo.bson.to.list(b, simplify = TRUE))
# not simplify
print(mongo.bson.to.list(b, simplify = FALSE))
# heterogeneous types of array values
print(mongo.bson.to.list(mongo.bson.from.list(list(x = list('a', 1))), simplify = TRUE))
# identical to call with simplify = F
print(mongo.bson.to.list(mongo.bson.from.list(list(x = list('a', 1))), simplify = FALSE))

Run the code above in your browser using DataLab