
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Map reduce your mongo documents writing in with coffeescript. As simple as it sounds! Finally you can organize and write your huge map/reduce/finalize functions in coffeescript syntax!
Run mongo_coffee:config generator to setup config files on your rails project. Then you can edit them as your needs:
$ rails g mongo_coffee:config
create config/mongo_coffee.yml
create config/initializers/mongo_coffee.rb
On mongo_coffee.yml file you'll find some config you might change:
coffee_path: 'app/models/map_reduces'
coffee_extensions:
- .js.coffee
- .coffee
The MongoCoffee compiler engine will search on coffee_path path (see setup section above) for files matching the following convention: %name%_%map/reduce/finalize%.js.coffee, i.e in the example below the following files should be ready in coffee_path directory (could be in some subdirectory):
Where this may be the content of the files:
playing_stats_map.js.coffee
->
emit
artirst: @artist
album: @album,
plays: 1
votes: 1
playing_stats_reduce.js.coffee
(key, values) ->
result =
plays: 0
votes: 0
for value in values
result.plays += value.plays
result.votes += value.votes
Have a look at the mongodb map/reduce documentation.
Call any of your map/reduce coffeescript collection with:
Band.caffeine_map_reduce('playing_stats').out(inline: 1)
If you've defined a finalize coffesript function you can also use it with:
Band.caffeine_map_reduce('playing_stats').caffeine_finalize('playing_stats').out(inline: 1)
As you may think, a map/reduce action will generate a new collection on MongoDB so, you may create it's model for interaction with new documents:
class PlayingStat
include Mongoid::Document
store_in collection: 'playing_stats'
field :value
index({"_id.artist" => 1},{background: true})
index({"_id.artist" => 1, "_id.album" => 1},{background: true})
def artist
_id["artist"]
end
def album
_id["album"]
end
def total_plays
value["plays"]
end
def total_votes
value["votes"]
end
end
This project uses MIT-LICENSE.
FAQs
Unknown package
We found that mongo_coffee demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.