diff --git a/packages/mongo-livedata/mongo_driver.js b/packages/mongo-livedata/mongo_driver.js index 3a9f2d7945..b749682988 100644 --- a/packages/mongo-livedata/mongo_driver.js +++ b/packages/mongo-livedata/mongo_driver.js @@ -1562,11 +1562,6 @@ var cursorSupportedByOplogTailing = function (cursorDescription) { // First, check the options. var options = cursorDescription.options; - // We don't yet implement field filtering for oplog tailing (just because it's - // not implemented, not because there's a deep problem with implementing it). - // XXX Implementing field filtering should be a priority. - if (options.fields) return false; - // This option (which are mostly used for sorted cursors) require us to figure // out where a given document fits in an order to know if it's included or // not, and we don't track that information when doing oplog tailing. diff --git a/packages/mongo-livedata/oplog.js b/packages/mongo-livedata/oplog.js index 37e200b6da..07706cd1dd 100644 --- a/packages/mongo-livedata/oplog.js +++ b/packages/mongo-livedata/oplog.js @@ -31,13 +31,16 @@ MongoConnection.prototype._observeChangesWithOplog = function ( var published = new IdMap; var selector = LocalCollection._compileSelector(cursorDescription.selector); + var projection = cursorDescription.options.fields ? + LocalCollection._compileProjection(cursorDescription.options.fields) : + EJSON.clone; var needToFetch = new IdMap; var currentlyFetching = new IdMap; var add = function (doc) { var id = doc._id; - var fields = EJSON.clone(doc); + var fields = projection(doc); delete fields._id; if (published.has(id)) throw Error("tried to add something already published " + id); @@ -52,8 +55,10 @@ MongoConnection.prototype._observeChangesWithOplog = function ( callbacks.removed && callbacks.removed(id); }; - // XXX mutates newDoc, that's weird + // XXX it doesn't mutate newDoc anymore since we apply projection function but + // be careful refactoring and moving out projection. var handleDoc = function (id, newDoc) { + newDoc = projection(newDoc); var matchesNow = newDoc && selector(newDoc); var matchedBefore = published.has(id); if (matchesNow && !matchedBefore) {