Skip to content

Instantly share code, notes, and snippets.

@kei-q
Created July 22, 2012 14:25
Show Gist options
  • Select an option

  • Save kei-q/3159851 to your computer and use it in GitHub Desktop.

Select an option

Save kei-q/3159851 to your computer and use it in GitHub Desktop.
# 以下ghci
# まずは結果を適当な名前(mrlout)を付けて記録
# それを対象にfindとかでqueryを投げる
# rSortは結局なにに使うのかわからなかった
> (Right cursor) <- access' $ DB.runMR' mapReduce {DB.rOut = DB.Output DB.Replace "mrlout" Nothing}
>(Right result) <- access' $ DB.find (DB.select [] "mrlout") {DB.sort=["value"=:1]}
dbname = "hoge"
access' action = do
pipe <- DB.runIOE $ DB.connect (DB.host "localhost")
DB.access pipe DB.master dbname action
mapFn = Bson.Javascript [] "function() {for(i in this.category) {emit(this.category[i], 1);}}"
reduceFn = Bson.Javascript [] "function(p, cur) {var c=0; for(i in cur){c+= cur[i];}; return c;}"
mapReduce = DB.mapReduce "Pkg" mapFn reduceFn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment