Store data into MongoDB with R

This is an document script to save data from .rep files into mongodb.

Interaction and creation of mongodb database:

miltonlab@miltonlab-Aspire-E5-471 ~/ $ mongo
MongoDB shell version: 2.6.10
connecting to: test
> use ikiam
switched to db ikiam
> db.createCollection("clima")

Dataset

img

Script of creation

library(jsonlite)
library(mongolite)

setwd('~/devs/ikiam/')
#TODO: file = readline("Input the file path to read: ")
data = read.delim('m5147/M5147_D1_F10_GPFT_R_160601000009.rep', 
                  sep="," ,
                  header = TRUE, 
                  colClasses = c('character', rep('numeric',124)))
selected = grep(pattern='X', x=colnames(data), value = FALSE)
columns <- colnames(data)[selected]
collection = mongo(collection="clima", db="ikiam")
for (i in 1:nrow(data)) {
  date <- strptime(data[i,'fecha'], "%Y%m%d%H%M%S", tz="")
  sensores <- data[i, columns]
  #TODO: remove the 'X' add by por R, not funtional at save time 
  # colnames(sensores) = sub("X", "", colnames(sensores))
  # Sin nombre para la segunda columna
  document <- data.frame(date=date, sensores)
  collection$insert(document)
}

Test Database

> db.clima.find.limit(1)

img