Basic handling for fields in oplog

Just run through projection before calling callbacks or keeping fields in published IdMap, or diffing.
This commit is contained in:
Slava Kim
2013-10-28 14:44:27 -07:00
committed by David Glasser
parent 74b4bd2bd6
commit adb46face0
2 changed files with 7 additions and 7 deletions

View File

@@ -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.

View File

@@ -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) {