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

Description Usage Arguments Details Value Note See Also Examples

View source: R/bson_convert.R

Description

Convert a list to a mongo.bson object.

Usage

1

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.

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.

Value

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

Note

Function converts unnamed R lists into bson arrays. It is very easy to construct bson object of any form using this function and list.

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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"]}

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