Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(RJSONIO)
- library(RCurl)
- httpPUT("http://127.0.0.1:5984/fooddb") # Creates the fooddb database
- # Add two documents
- fromJSON(getURL("http://127.0.0.1:5984/fooddb", customrequest='POST', httpheader=c('Content-Type'='application/json'), postfields=toJSON(list(day="Monday", dinner="Pasta"))))
- fromJSON(getURL("http://127.0.0.1:5984/fooddb", customrequest='POST', httpheader=c('Content-Type'='application/json'), postfields=toJSON(list(day="Tuesday", dinner="Soup"))))
- function(doc) {
- emit(doc.day, doc.dinner);
- }
- view.results <- fromJSON(httpGET("http://127.0.0.1:5984/fooddb/_design/fooddoc/_view/foodview"))
- view.results.df <- do.call(rbind.data.frame, view.results$rows)
- colnames(view.results.df) <- c("key", "day", "dinner")
- writeLines(toJSON("function(doc) {
- emit(doc.day, doc.dinner);
- }"),
- "foodview.json")
- fromJSON(getURL("http://127.0.0.1:5984/fooddb/_design/foodview", customrequest='PUT', httpheader=c('Content-Type'='application/json'), postfields="@foodview.json"))
- writeLines("{
- "_id": "_design/foodview",
- "views": {
- "foodview": {
- "map": "function(doc) {emit(doc.day, doc.dinner);}"
- }
- }
- }"
- , "foodview.json")
- fromJSON(getURL("http://127.0.0.1:5984/fooddb/_design/foodview", customrequest='PUT', httpheader=c('Content-Type'='application/json'), postfields="@foodview.json"))
- {
- "_id": "_design/foodview",
- "views": {
- "foodview": {
- "map": "function(doc) {emit(doc.day, doc.dinner);}"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement