Learn R Programming

rmongodb

This is an R (www.r-project.org) extension supporting access to MongoDB (www.mongodb.org) using the mongodb-c-driver (http://docs.mongodb.org/ecosystem/drivers/c/).

The latest stable version is available on CRAN: http://cran.r-project.org/package=rmongodb

Thanks to Gerald Lindsly and MongoDB, Inc. (formerly 10gen) for the initial work.

In October 2013, MongoSoup and Markus Schmidberger have overtaken the development and maintenance of the R package.

Since October 2014 package is maintained by Dmitriy Selivanov. Please feel free to send us issues or pull requests via github: https://github.com/mongosoup/rmongodb

Furthermore, I'm happy to get your feedback personally via email: selivanov.dmitriy (at) gmail.com.

Usage

Once you have installed the package, it may be loaded from within R like any other package:

library("rmongodb")

# connect to your local mongodb
mongo <- mongo.create()

# create query object 
query <- mongo.bson.from.JSON('{"age": 27}')

# Find the first 100 records
#    in collection people of database test where age == 27
cursor <- mongo.find(mongo, "test.people", query, limit=100L)
# Step though the matching records and display them
while (mongo.cursor.next(cursor))
    print(mongo.cursor.value(cursor))
mongo.cursor.destroy(cursor)

res <- mongo.find.batch(mongo, "test.people", query, limit=100L)

mongo.disconnect(mongo)
mongo.destroy(mongo)

There is also one demo available:

library("rmongodb")
demo(teachers_aid)

Supported Functionality by rmongodb

  • Connecting and disconnecting to MongoDB
  • Querying, inserting and updating to MongoDB including with JSON and BSON
  • Creating and handling BSON objects
  • Dropping collections and databases on MongoDB
  • Creating indices on MongoDB collections
  • Error handling
  • Executing commands on MongoDB
  • Adding, removing, handling files on a "Grid File System" (GridFS) on a

MongoDB server

Good ressources to Get Started with rmongodb

Good ressources to Install and Get Started with MongoDB

Good ressources for working with JSON-Data in R:

Development

To install the development version of rmongodb, it's easiest to use the devtools package:

# install.packages("devtools")
library(devtools)
install_github("mongosoup/rmongodb")

We advice using RStudio (www.rstudio.org) for the package development. The RStudio .Rproj file is included in the repository.

Usefull links

Versioning

We use a three step version number system, e.g. v1.2.1:

  • first: major changes as new C libraries
  • second: for each new stable CRAN release
  • third: for each new github version ready for testing

General Development Rules

  • we use roxygen2
  • we write RUnit tests for all new functionality in tests/test_XXX.R
  • for bigger changes we use branches
  • run valgrid to check for memory leaks R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < test_XXX.R > log.txt 2>&1
  • CRAN submission:
  • http://cran.r-project.org/submit.html
  • create Package tar.gz via RStudio "Build Source Package"
  • run R CRAN checks via: R CMD check --as-cran package.tar.gz
  • run R CRAN checks without running mongodb installation
  • create a tag / release on github for every CRAN submission

Copy Link

Version

Install

install.packages('rmongodb')

Monthly Downloads

128

Version

1.8.0

License

Apache License 2.0

Issues

Pull Requests

Stars

Forks

Last Published

November 12th, 2014

Functions in rmongodb (1.8.0)

mongo.bson.buffer.append.code.w.scope

Append a code field with a scope onto a mongo.bson.buffer
mongo.bson

The mongo.bson class
mongo.bson.buffer.append.bool

Append a boolean field onto a mongo.bson.buffer
mongo.bson.from.df

Convert a data.frame to a mongo.bson object
mongo.binary.uuid

BSON binary data subtype constant for uuid data
mongo.bson.buffer.append.oid

Append a OID into a mongo.bson.buffer
mongo.binary.binary

BSON binary data subtype constant for standard binary data
mongo.add.user

Add a user and password
mongo.bson.buffer.finish.object

Finish a subobject or array within a mongo.bson.buffer
mongo.binary.md5

BSON binary data subtype constant for md5 data
mongo.bson.to.Robject

Convert a mongo.bson object to an R object.
mongo.bson.buffer.append.int

Append an integer field onto a mongo.bson.buffer
mongo.find

Find records in a collection
mongo.binary.old

BSON binary data subtype constant for old format data
mongo.aggregation

Aggregation pipeline
mongo.bson.string

BSON data type constant for a string value
mongo.bson.null

BSON data type constant for a null value
mongo.bson.binary

BSON data type constant for a binary data value
mongo.bson.buffer.append.object

Append an R object onto a mongo.bson.buffer
mongo.bson.code.w.scope

BSON data type constant for a code with scope value
mongo.bson.eoo

BSON data type constant for 'End Of Object'
mongo.bson.iterator.key

Return the key (name) of the field pointed to by an iterator
mongo.bson.buffer.append.code

Append a code field onto a mongo.bson.buffer
mongo.bson.object

BSON data type constant for a subobject value
mongo.get.database.collections

Get a list of collections in a database
mongo.binary.user

BSON binary data subtype constant for user data
mongo.bson.buffer.append.undefined

Append a undefined field onto a mongo.bson.buffer
mongo.bson.buffer.append.time

Append a time value into a mongo.bson.buffer
mongo.bson.long

BSON data type constant for a long value
mongo.get.server.err.string

Retrieve an server error code from a mongo connection object
mongo.bson.buffer.append.bson

Append a mongo.bson object into a mongo.bson.buffer
mongo.find.no.cursor.timeout

mongo.find flag constant - no cursor timeout
mongo.bson.buffer.size

Get the size of a mongo.bson.buffer object
mongo.bson.buffer.append.raw

Append a raw (binary) field onto a mongo.bson.buffer
mongo.bson.empty

Create an empty mongo.bson object
mongo.bson.iterator.create

Create a mongo.bson.iterator object
mongo.find.await.data

mongo.find flag constant - await data
mongo.bson.buffer.append.list

Append a list onto a mongo.bson.buffer
mongo.bson.iterator.type

Get the type of data pointed to by an iterator
mongo.bson.symbol

BSON data type constant for a symbol value
mongo.bson.double

BSON data type constant for a double value
mongo.binary.function

BSON binary data subtype constant for function data
mongo.bson.buffer.append.double

Append a double field onto a mongo.bson.buffer
mongo.bson.from.buffer

Convert a mongo.bson.buffer object to a mongo.bson object
mongo.get.databases

Get a list of databases from a MongoDB server
mongo.gridfile.get.metadata

Get the metadata of a mongo.gridfile
mongo.cursor.to.list

Convert Mongo Cursor Object to List so that each element of resulting list represents document in source collection.
mongo.cursor.value

Fetch the current value of a cursor
mongo.find.oplog.replay

mongo.find flag constant - oplog replay
mongo.cursor.to.data.frame

Convert Mongo Cursor Object to Data.Frame
mongo.bson.from.JSON

Convert JSON to BSON Object
mongo.bson.value

Return the value of a mongo.bson field
mongo.bson.buffer.append.string

Append a string field onto a mongo.bson.buffer
mongo.authenticate

Autherticate a user and password
mongo.bson.buffer.append.timestamp

Append a timestamp value into a mongo.bson.buffer
mongo.bson.buffer.append.long

Append a long valued field onto a mongo.bson.buffer
mongo.bson.buffer.append.null

Append a double field onto a mongo.bson.buffer
mongo.bson.buffer.start.object

Start a subobject within a mongo.bson.buffer
mongo.bson.array

BSON data type constant for an array
mongo.drop.database

Drop a database from a MongoDB server
mongo.bson.buffer.append.element

Append a mongo.bson.iterator's element into a mongo.bson.buffer
mongo.bson.iterator.next

Advance an iterator to the first or next field
mongo.code.w.scope

The mongo.code.w.scope class
mongo.bson.size

Get the size of a mongo.bson object
mongo.code.create

Create a mongo.code object
mongo.bson.buffer.append.symbol

Append a symbol field onto a mongo.bson.buffer
mongo.gridfs.find

Find a GridFS file
mongo.bson.int

BSON data type constant for a integer value
mongo.index.sparse

mongo.index.create flag constant - sparse
mongo.code.w.scope.create

Create a mongo.code.w.scope object
mongo.bson.dbref

BSON data type constant for a dbref value
mongo.gridfile.get.content.type

Get the content type of a mongo.gridfile
as.character.mongo.oid

Convert a mongo.oid object to a string
mongo.drop

Drop a collection from a MongoDB server
mongo.bson.buffer.append.complex

Append a double field onto a mongo.bson.buffer
mongo.get.prev.err

Retrieve an server error code from a mongo connection object
mongo.bson.timestamp

BSON data type constant for a timestamp value
mongo.gridfile

The mongo.gridfile class
mongo.gridfile.writer

The mongo.gridfile.writer class
mongo.count

Count records in a collection
mongo.bson.buffer.create

Create an new mongo.bson.buffer object
mongo.gridfile.read

Read raw data from a mongo.gridfile
mongo.gridfile.writer.finish

Finish writing to a buffered GridFS file
mongo.bson.buffer.append

Append a name/value pair into a mongo.bson.buffer
mongo.bson.code

BSON data type constant for a code value
mongo.gridfile.writer.create

Create a mongo.gridfile.writer object
mongo.gridfile.pipe

Pipe a mongo.gridfile to an R connection
mongo.bson.date

BSON data type constant for a date value
mongo.gridfile.destroy

Destroy a mongo.gridfile object
mongo.bson.iterator.value

Return the value of the field pointed to by an iterator
mongo.gridfile.get.chunk.count

Get the chunk count of a mongo.gridfile
mongo.bson.buffer.append.regex

Append a timestamp value into a mongo.bson.buffer
print.mongo.bson

Display a mongo.bson object
mongo.bson.oid

BSON data type constant for a oid value
mongo.bson.destroy

Destroy a mongo.bson object
mongo.set.timeout

Set the timeout value on a mongo connection
mongo.code

The mongo.code class
mongo.rename

Rename a collection on a MongoDB server
mongo.bson.to.list

Convert a mongo.bson object to an R list object.
mongo.bson.buffer.start.array

Start an array within a mongo.bson.buffer
mongo.bson.print

Display a mongo.bson object
mongo.bson.bool

BSON data type constant for a bool value
mongo.bson.from.list

Convert a list to a mongo.bson object
mongo.find.exhaust

mongo.find flag constant - exhaust
mongo.create

Create an object of class "mongo"
mongo.get.err

Retrieve an connection error code from a mongo object
mongo.gridfile.get.chunk

Get a chunk of a mongo.gridfile
mongo.bson.iterator

The mongo.bson.iterator class
mongo.oid.time

Get an Object ID's time
mongo.destroy

Destroy a MongoDB connection
mongo.gridfile.get.length

Get the length of a mongo.gridfile
mongo.find.partial.results

mongo.find flag constant - partial results
mongo.bson.undefined

BSON data type constant for a undefined value
mongo.get.hosts

Get a lists of hosts & ports as reported by a replica set master upon connection creation.
mongo.symbol

The mongo.symbol class
mongo.index.create

Add an index to a collection
mongo.bson.find

Find a field within a mongo.bson object by name
mongo.oid.create

Create a mongo.oid object
mongo.index.unique

mongo.index.create flag constant - unique keys
mongo.get.primary

Get the host & port of the server to which a mongo object is connected.
mongo.oid.print

Display a mongo.oid object
mongo.bson.regex

BSON data type constant for a regex value
mongo.gridfs.destroy

Destroy a mongo.gridfs object
mongo.disconnect

Disconnect from a MongoDB server
mongo.get.server.err

Retrieve an server error code from a mongo connection object
mongo.index.background

mongo.index.create flag constant - background
mongo.gridfs.remove.file

Remove a file from a GridFS on a MongoDB server
mongo.simple.command

Issue a simple.command to a database on MongoDB server
mongo.find.cursor.tailable

mongo.find flag constant - cursor tailable
mongo.command

Issue a command to a database on MongoDB server
mongo.symbol.create

Create a mongo.symbol object
mongo.cursor.next

Advance a cursor to the next record
mongo.gridfs.store

Store raw data as a file in a GridFS
mongo.gridfile.writer.write

Write raw data to a buffered GridFS file
mongo.cursor

The mongo.cursor class
mongo.find.one

Find one record in a collection
mongo.insert.batch

Add multiple records to a collection
mongo.update.multi

mongo.update() flag constant for updating multiple records
mongo.index.drop.dups

mongo.index.create flag constant - drop duplicate keys
mongo.gridfile.get.descriptor

Get the descriptor of a mongo.gridfile
mongo.get.socket

Get the socket assigned to a mongo object by mongo.create().
mongo.timestamp

The mongo.timestamp class
mongo.reconnect

Reconnect to a MongoDB server
mongo.is.master

Determine if a mongo connection object is connected to a master
mongo.gridfs

The mongo.gridfs class
mongo.find.all

Find records in a collection and returns one R data frame object
mongo.gridfs.store.file

Store a file into a GridFS on a MongoDB server
mongo.gridfile.get.chunks

Get a cursor for a range of chunks in a mongo.gridfile
mongo.cursor.destroy

Release resources attached to a cursor
mongo.shorthand

Define shorthand for BSON and GridFS
mongo.find.slave.ok

mongo.find flag constant - slave ok
mongo.is.connected

Determine if a mongo object is connected to a MongoDB server
mongo.remove

Remove records from a collection
mongo.gridfile.seek

Seek to a position in a mongo.gridfile
mongo.gridfile.get.md5

Get the MD5 hash of a mongo.gridfile
mongo.get.timeout

Get the timeout value of a mongo connection
mongo.update.basic

mongo.update() flag constant for performing a basic update
print.mongo.oid

Display a mongo.oid object
mongo.gridfs.create

Create a mongo.gridfs object
mongo.undefined

The mongo.undefined class
zips

zips Dataset
mongo.reset.err

Retrieve an server error code from a mongo connection object
mongo.timestamp.create

Create a mongo.timestamp object
mongo.regex

The mongo.regex class
mongo.index.TTLcreate

Add a time to live (TTL) index to a collection
mongo.distinct

Get a vector of distinct values for keys in a collection
mongo.regex.create

Create a mongo.regex object
mongo.gridfile.get.filename

Get the filename of a mongo.gridfile
mongo.oid.to.string

Convert a mongo.oid object to a string
mongo.get.last.err

Retrieve an server error code from a mongo connection object
mongo

The mongo (database connection) class
mongo.gridfile.get.chunk.size

Get the chunk.size of a mongo.gridfile
mongo.bson.buffer

The mongo.bson.buffer class
mongo.update

Perform an update on a collection
mongo.oid

The mongo.oid class
mongo.insert

Add record to a collection
mongo.update.upsert

mongo.update() flag constant for an upsert
mongo.oid.from.string

Create a mongo.oid object ftom a string
mongo.gridfile.get.upload.date

Get the upload date of a mongo.gridfile
mongo.undefined.create

Create a mongo.undefined object