I have a few MongoDb Capped Collections and I'm attempting to stream new entries (from another process) out to my page over SocketIO like so:
Server side:
...
var TickerSchema = new Mongoose.Schema({
bid : { type : Number },
ask : { type : Number },
mid : { type : Number },
last_price : { type : Number },
timestamp : { type : Date }
}, { capped: { size: 5242880, max: 1000, autoIndexId: true }});
var tickerStream = Ticker.find().tailable().stream();
ioserver.sockets.on('connection', function(socket){
clientsocket = socket;
tickerStream.on('data', function (doc) {
clientsocket.emit('ticker', doc);
}).on('error', function (err) {
console.log('error: '+err);
}).on('close', function () {
// the stream is closed
system.debug('close');
});
...
Client side:
var socket = io.connect('http://localhost');
function TickerController($scope, $http, $window)
{
$scope.ticker = null;
$scope.init = function(){
}
$window.socket.on('ticker', function(ticker){
console.log(ticker);
$scope.$apply(function(){
$scope.ticker = ticker;
});
});
}
But when I run the app, I get the new events, but I get 2-3 of them instead of just 1 new document being inserted.
I've checked the collection and it doesn't have the duplicates - I do have multiple channels on the same socket could this be the issue?
