• Stars
    star
    281
  • Rank 147,023 (Top 3 %)
  • Language
    C
  • Created about 10 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast and Simple MongoDB Client for R

mongolite

Fast and Simple MongoDB Client for R

CRAN_Status_Badge CRAN RStudio mirror downloads Research software impact

High-level, high-performance MongoDB client based on libmongoc and jsonlite. Includes support for aggregation, indexing, map-reduce, streaming, SSL encryption and SASL authentication. The vignette gives a brief overview of the available methods in the package.

Documentation

About the R package:

Hello World

Example using a public test server

con <- mongo("mtcars", url =
  "mongodb+srv://readwrite:[email protected]/test")

# Wipe collection
if(con$count() > 0) 
  con$drop()
  
# Insert some data
con$insert(mtcars)
stopifnot(con$count() == nrow(mtcars))

# Query data
mydata <- con$find()
stopifnot(all.equal(mydata, mtcars))
con$drop()

# Automatically disconnect when connection is removed
rm(con)
gc()

Insert/retrieve data from your local mongodb server:

# Init connection to local mongod
library(mongolite)
m <- mongo(collection = "diamonds")

# Insert test data
data(diamonds, package="ggplot2")
m$insert(diamonds)

# Check records
m$count()
nrow(diamonds)

# Perform a query and retrieve data
out <- m$find('{"cut" : "Premium", "price" : { "$lt" : 1000 } }')

# Compare
nrow(out)
nrow(subset(diamonds, cut == "Premium" & price < 1000))

More advanced features include map reduce:

# Cross-table
tbl <- m$mapreduce(
  map = "function(){emit({cut:this.cut, color:this.color}, 1)}",
  reduce = "function(id, counts){return Array.sum(counts)}"
)
# Same as:
data.frame(with(diamonds, table(cut, color)))

Importing and exporting json or bson data:

# Stream jsonlines into a connection
tmp <- tempfile()
m$export(file(tmp))

# Stream it back in R
library(jsonlite)
mydata <- stream_in(file(tmp))

# Or into mongo
m2 <- mongo("diamonds2")
m2$count()
m2$import(file(tmp))
m2$count()

# Remove the collection
m$drop()
m2$drop()

Installation

Binary packages for OS-X or Windows can be installed directly from CRAN:

install.packages("mongolite")

Installation from source on Linux requires openssl and Cyrus SASL (not GNU sasl). On Debian or Ubuntu use libssl-dev and libsasl2-dev:

sudo apt-get install -y libssl-dev libsasl2-dev

On Fedora, CentOS or RHEL use openssl-devel and cyrus-sasl-devel:

sudo yum install openssl-devel cyrus-sasl-devel

More Repositories

1

jsonlite

A Robust, High Performance JSON Parser and Generator for R
C
361
star
2

curl

A Modern and Flexible Web Client for R
C
207
star
3

resttesttest

A native in-browser tool for testing REST/CORS services. Builds on jQuery and Bootstrap.
HTML
195
star
4

V8

Embedded JavaScript Engine for R
C++
188
star
5

sys

Powerful replacements for base::system2
C
102
star
6

js

Tools for Working with JavaScript in R
R
67
star
7

openssl

OpenSSL bindings for R
R
64
star
8

RAppArmor

R interfaces to Linux and AppArmor security methods
TeX
52
star
9

protolite

Fast and Simple Object Serialization to Protocol Buffers
C++
47
star
10

opencpu-legacy

This version is no longer maintained. Switch to "opencpu" repository.
R
41
star
11

solarisvm

VMware image with R on Solaris
32
star
12

webutils

Utility functions for web applications
R
23
star
13

shinymagick

Simple Demo of using Magick with Shiny
R
22
star
14

unix

R bindings to system utilities found in most Unix systems
R
21
star
15

agent

Store sensitive data such as API tokens
R
19
star
16

gpg

Bindings to gpgme for R
C
19
star
17

bcrypt

Wrapper for bcrypt in R
C
17
star
18

webp

R bindings for libwebp
R
14
star
19

tidyhtml

R bindings to html-tidy C interface
C
14
star
20

maketools

Exploring and Testing your Toolchain Configuration and System Packages
R
14
star
21

ipfs

R bindings to IPFS
R
10
star
22

popplertest

Example code to test string encoding in poppler-cpp
C++
10
star
23

build-v8-static

Building static v8-monolith library for various distros
Dockerfile
10
star
24

imwidgets

HTML widgets for viewing images
JavaScript
9
star
25

user2021

Slides from UseR-2021 keynote presentation about R-universe
HTML
7
star
26

snapshot

Create snapshots of R package repositories
R
6
star
27

rjade

R Bindings to the Jade Templating Engine
R
6
star
28

yeroon

yeroon.net webapps
JavaScript
5
star
29

badgen

R
5
star
30

betty

Some experimental rOpenSci infrastructure plumbing
R
5
star
31

Ohmage

Ohmage R package
R
5
star
32

ndjson-benchmark

Simple benchmark to compare jsonlite, ndjson, corpus
4
star
33

yeroon-setup

JavaScript
4
star
34

r-dependency-versioning

CSS
4
star
35

opencpu.tools

some tools for the opencpu project
R
4
star
36

backup

4
star
37

markdownit

Bindings to markdown-it JavaScript library
R
3
star
38

minimist

R binding to minimist JavaScript library
R
3
star
39

slides

Slides for the defense presentation
CSS
2
star
40

Mobilize

Mobilize R package
R
2
star
41

lmergm

lmergm R package
R
2
star
42

ohmage-ubuntu

ohmage-ubuntu
Shell
2
star
43

base64

R
2
star
44

debugcurl

How to debug curl (because I keep forgetting)
2
star
45

pacmantools

Tools for pacman repos
R
1
star
46

maintest

Test with main repository
HTML
1
star
47

JJcorr

Git repo for the JJcorr package
R
1
star
48

interactivity

cran-interactivity
C
1
star
49

r-security

R
1
star
50

r-universe

1
star
51

autobrew-old

Scripts for brewing static libs on CRAN MacOS builder
Roff
1
star
52

brotli

C
1
star
53

testinterrupt

Package + readme to demonstrate the user interruption problem in R
C
1
star
54

grenoble2015

Automatically exported from code.google.com/p/io-2012-slides
CSS
1
star
55

uptest

C++
1
star