Skip to content

Instantly share code, notes, and snippets.

@kyriesent
Created February 12, 2013 20:45
Show Gist options
  • Save kyriesent/4773222 to your computer and use it in GitHub Desktop.
Save kyriesent/4773222 to your computer and use it in GitHub Desktop.
itemSchema:
tagsL: [String]
itemSchema.pre 'save', (next) ->
#determine which fields will be inc'd/dec'd
itemSchema.post 'save', (next) ->
#on successful save, inc or dec tags accordingly
tagSchema:
tagL: String
c: Number
tagSchema.statics.recount, (done) ->
#use mongoose MapReduce to recount the tags and compile the numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment