Mongoose FeedItems
A simple news feed system for a mongoose.js backed node.js application.
How it works
Creates a FeedItem collection whose documents have the following attributes:
- actor - the user who caused the feed item to be created
- createdAt - a timestamp of when the item was created
- sourceId - the mongoDB id of the source item
- sourceType - the name of the collection containing the source item
Adds methods and callbacks to other models which create and remove feedItems when they are created or destroyed.
Example
# # Setup models # mongooseFeeditems = require"mongoose-feeditems" mongoose = require"mongoose" ThingToTrackSchema = mongooseSchemanew name: 'String' ThingToTrackSchemaplugin mongooseFeedItemtrackerfeedCollection: 'FeedItem' mongoosemodel 'ThingToTrack'ThingToTrackSchema FeedItemSchema = mongooseSchemanew FeedItemSchemaplugin mongooseFeedItemfeedCollection # # Use em # ThingToTrack = mongoosemodel"ThingToTrack"FeedItem = mongoosemodel"FeedItem" thing = name: 'Fish' thingsave consolelog 'thing saved!' FeedItemfindexec consolelog 'feedItems'feedItems # => will contain a feedItem with the source set to the thing. feedItems0fetchSource consolelog 'source'source # => will print the thing