read_bson function

Standalone BSON reader

Standalone BSON reader

Reads BSON data from a mongoexport dump file directly into R (if it can fit in memory). This utility does not attempt to convert result into one big single data.frame: the output is always a vector of length equal to total number of documents in the collection.

read_bson(file, as_json = FALSE, simplify = TRUE, verbose = interactive())

Arguments

  • file: path or url to a bson file
  • as_json: read data into json strings instead of R lists.
  • simplify: should nested data get simplified into atomic vectors and dataframes where possible? Only used for as_json = FALSE.
  • verbose: print some progress output while reading

Details

It is enabled by default to simplify the individual data documents using the same rules as jsonlite . This converts nested lists into atomic vectors and data frames when possible, which makes data easier to work with in R.

An alternative to this function is to import your BSON file into a local mongodb server using the mongo$import() function. This requires little memory and once data is in mongodb you can easily query and modify it.

Examples

diamonds <- read_bson("https://jeroen.github.io/data/diamonds.bson") length(diamonds)
  • Maintainer: Jeroen Ooms
  • License: Apache License 2.0
  • Last published: 2025-03-17