![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
mongodb-activity-feed
Advanced tools
Activity Feeds, Timeline, Notification Feed, News Feed with MongoDB, Mongo
Simple example of how to build a news feed with Node and MongoDB. I created it for this blogpost: "Building Activity Feeds with MongoDB vs the alternatives"
https://docs.google.com/document/d/11gfMOPgE476fLsb2sXYy955X2G4egUv4p7-zlXdf8hU/edit
It uses CRDTs to reduce the need for locks.
yarn add mongodb-activity-feed
brew install redis mongodb
brew services start redis
brew services start mongodb
Here's a very short example
import { FeedManager } from 'mongodb-activity-feed'
const fm = new FeedManager(mongoConnection, redisConnection, {
bull: false,
firehose: false,
})
And a bit longer one:
import {FeedManager, FayeFirehose} from 'mongodb-activity-feed'
import Redis from 'ioredis'
import mongoose from 'mongoose'
const redis = new Redis('redis://localhost:6379/9')
const mongo = mongoose.connect(
'mongodb://localhost:27017/mydb',
{
autoIndex: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 500,
poolSize: 50,
bufferMaxEntries: 0,
keepAlive: 120,
},
)
const fayeFirehose = new FayeFirehose('http://localhost:8000/faye')
const fm = new FeedManager(mongo, redis, {bull: true, firehose: fayeFirehose})
The bull option determines if activity fanout is done over a bull queue or synchronous. The firehose option allows you to listen to feed changes in realtime using Faye.
Here's a quick tutorial on a simple timeline with mongodb-activity-feed
const timelineScott = await fm.getOrCreateFeed('timeline', 'scott')
const userNick = await fm.getOrCreateFeed('user', 'nick')
await fm.follow(timelineScott, userNick)
const activity = {
actor: 'user:nick',
verb: 'watch',
object: 'video:123',
}
await fm.addActivity(activity, userNick)
const activities = await fm.readFeed(timelineScott, 0, 10)
Here's a quick tutorial on a simple timeline with mongodb-activity-feed
const notificationBen = await fm.getOrCreateFeed('notification', 'ben')
// lets say you want to notify Ben that Nick likes his post
const activity = {
actor: 'user:nick',
verb: 'like',
object: 'post:123',
}
await fm.addActivity(activity, notificationBen)
// group together all activities with the same verb and actor
const aggregationMethod = activity => {
return activity.verb + '__' + activity.actor
}
const groups = await fm.readFeed(notificationBen, 0, 3, null, aggregationMethod)
Add an activity like this.
const activity = {
actor: 'user:nick',
verb: 'like',
object: 'post:123',
}
fm.addActivity(activity, feed)
Remove an activity:
const activity = {
actor: 'user:nick',
verb: 'like',
object: 'post:123',
}
fm.removeActivity(activity, feed)
// follow with a copy limit of 10
const timelineScott = await fm.getOrCreateFeed('timeline', 'scott')
const userNick = await fm.getOrCreateFeed('user', 'nick')
await fm.follow(timelineScott, userNick, 10)
// follow with a copy limit of 10
const source = await fm.getOrCreateFeed('timeline', 'scott')
const target = await fm.getOrCreateFeed('user', 'nick')
const target2 = await fm.getOrCreateFeed('user', 'john')
await fm.followMany([{source, target}, {source, target2}], 10)
const timelineScott = await fm.getOrCreateFeed('timeline', 'scott')
const userNick = await fm.getOrCreateFeed('user', 'nick')
await fm.unfollow(timelineScott, userNick)
const feedReferences = [{group: 'timeline', feedID: 'scott'}, {group: 'notification', feedID: 'ben'}]
const feedMap = await fm.getOrCreateFeeds(feedReferences)
const notificationAlex = await fm.getOrCreateFeed('notification', 'alex')
await fm.readFeed(notificationAlex, 0, 10)
const notificationAlex = await fm.getOrCreateFeed('notification', 'alex')
// asumes that you have a property on your activity called "popularity"
const rankingMethod = (a, b) => {
return b.popularity - a.popularity
}
const activities = await fm.readFeed(notificationAlex, 0, 3, rankingMethod)
const notificationAlex = await fm.getOrCreateFeed('notification', 'alex')
// group together all activities with the same verb and actor
const aggregationMethod = activity => {
return activity.verb + '__' + activity.actor
}
await fm.readFeed(notificationAlex, 0, 10, null, aggregationMethod)
Activities are unique on the combination of foreign_id
and time
.
If you don't specify foreign id the full activity object will be used.
MongoDB is a nice general purpose database. For building activity feeds it's not a great fit though. Cassandra and Redis will in most scenarios outperform a MongoDB based solution.
Dedicated activity feed databases like Stream are typically 10x more performant and easier to use.
So in most cases you shouldn't run your activity feed on MongoDB. It only makes sense if your traffic is relatively small and you're not able to use cloud hosted APIs. Unless you really need to run your feeds on-prem you should not use this in prod.
If you do need to run on-prem I'd recommend the open source Stream-Framework
Pull requests are welcome but be sure to improve test coverage.
yarn test
yarn lint
yarn prettier
FAQs
Activity Feeds, Timeline, Notification Feed, News Feed with MongoDB, Mongo
The npm package mongodb-activity-feed receives a total of 3 weekly downloads. As such, mongodb-activity-feed popularity was classified as not popular.
We found that mongodb-activity-feed 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.