Reading data from NoSQL databases – MongoDB

Unlike relational databases for which a somewhat standard approach works across all relational databases, the fluid state of NoSQL databases means that no such standard approach has yet evolved. We illustrate this with MongoDB using the rmongodb package.

Getting ready

Prepare the environment by following these steps:

  1. Download and install MongoDB.
  2. Start mongod as a background process and then start mongo.
  3. Create a new database customer and a collection called orders:
    > use customer
    > db.orders.save({customername:"John", orderdate:ISODate("2014-11-01"),orderamount:1000})
    > db.orders.find()
    > db.save

How to do it...

To read data from MongoDB, follow these steps:

  1. Install the rmongodb package and create a connection: ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.