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

Description Usage Arguments Value Note See Also Examples

View source: R/bson_convert.R

Description

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

Usage

1
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

Note

Now arrays in bson document are 1) converted into unnamed lists 2) If simplify == TRUE, function tries to turn arrays of primitive types into R vectors. Please see examples below;

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 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))

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.