Skip to content

Instantly share code, notes, and snippets.

@ssimeonov
Created August 23, 2012 03:32
Show Gist options
  • Save ssimeonov/3431917 to your computer and use it in GitHub Desktop.
Save ssimeonov/3431917 to your computer and use it in GitHub Desktop.
Storing & retrieving proto objects from MongoDB
add = function(., name, p) {
data <- list(name=name, type=p$..Name, data=as.list(p))
.$collection()$insert(data)
},
get = function(., name) {
doc <- .$collection()$query_one(name=name)
if (!is.null(doc)) {
factory <- base:::get(doc$type, pos=1)
do.call(factory$new, doc$data)
} else {
NULL
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment