Skip to content

Instantly share code, notes, and snippets.

@bitmage
Created July 1, 2013 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitmage/5905673 to your computer and use it in GitHub Desktop.
Save bitmage/5905673 to your computer and use it in GitHub Desktop.
testing Mongo stream API
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