Created
July 1, 2013 23:46
-
-
Save bitmage/5905673 to your computer and use it in GitHub Desktop.
testing Mongo stream API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongo = require('mongodb'); | |
var client = new mongo.Db('test', new mongo.Server('localhost', 27017), {w: 1}); | |
// connect to DB and insert a record | |
client.open(function(err) { | |
client.collection('users', function(err, users) { | |
users.insert({email: 'graham@daventry.com'}, function(err) { | |
// listen for changes | |
var stream = users.find().stream(); | |
stream.on('data', function(event) { | |
return console.log({event: event}); | |
//EXPECTED: should receive insert/update events | |
//ACTUAL: receive record after both changes | |
}); | |
// request an update | |
users.update( | |
{email: 'graham@daventry.com'}, | |
{$set: { name: 'Graham' }}, | |
function() {} | |
); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment