Setup:
$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
$ npm install mongodb
Subscribe:
$ node subscribe.js
Publish:
$ mongo
> use pubsub
> db.messages.insert({ message: 'Hello world', time: Date.now() })
Update for the 2019s - mongodb 3.3.4 or similar