Skip to content

Instantly share code, notes, and snippets.

@cecilialee
Last active June 21, 2019 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecilialee/7d7e7e6517c0c2c1b3a37b4b72854e8c to your computer and use it in GitHub Desktop.
Save cecilialee/7d7e7e6517c0c2c1b3a37b4b72854e8c to your computer and use it in GitHub Desktop.
Read and write pdf to MongoDB with mongolite in R #r #mongolite
library(dplyr)
library(mongolite)
# MongoDB connection
m <- mongo("listcopro")
# Read raw data
file <- file("/Users/cecilialee/Dropbox/dropbox/freelance/listcopro/bitbucket/recruitment/test/data/resume_1.pdf", "rb")
data <- readBin(file, "raw", 9999999)
# Save to database
m$insert(list(id = "01", cv = data))
# Retrieve the inserted cv
cv <- as.raw(m$find('{"id":"01"}')$cv[[1]])
# Output cv
writeBin(cv, "resume_1_mongo.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment