Extends mongolite with finddt() and aggregatedt() that return data.table objects.
finddt and aggregatedt are faster implementations of mongolite::find and mongolite::aggregate.
Important
To use these functions the query sent to mongodb should return data that can be coerced into a data.table (using data.table::rbindlist). If not, the queries will return an error.
See vignettes for detailed exampels
Define a mongolite::mongo connection object
Then call bind_mongolitedt(mongo) to bind the finddt() and aggregatedt() functions
Then use the functions as you would standard mongolite functions:
mongo <- mongolite::mongo(collection = "test", db = "test", url = "mongodb://localhost") bind_mongolitedt(mongo) ## return 10 rows of a data.table mongo$finddt(limit = 10)
some quick benchmarks:
mongo$find 1,000,000 documents at pagesize 100000 ~30 seconds.mongo$finddt 1,000,000 documents at pagesize 100000 ~10 seconds
mongo$find - 5,000,000 documents at pagesize 100000 ~157 seconds
mongo$finddt - 5,000,000 documents at pagesize 100000 ~60 seconds### install development version from github
devtools::install_github("SymbolixAU/mongolitedt")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.