mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Oplog observe handles 'drop collection' or db.c.drop()
This commit is contained in:
@@ -258,8 +258,10 @@ MongoConnection.prototype._startOplogTailing = function (oplogUrl,
|
||||
var baseOplogSelector = _.once(function () {
|
||||
return {
|
||||
ns: new RegExp('^' + quotemeta(dbNameFuture.wait()) + '\\.'),
|
||||
// XXX also handle drop collection, etc
|
||||
op: {$in: ['i', 'u', 'd']}
|
||||
$or: [
|
||||
{ op: {$in: ['i', 'u', 'd']} },
|
||||
// If it is not db.collection.drop(), ignore it
|
||||
{ op: 'c', 'o.drop': { $exists: true } }]
|
||||
};
|
||||
});
|
||||
// XXX doc
|
||||
@@ -403,6 +405,11 @@ MongoConnection.prototype._startOplogTailing = function (oplogUrl,
|
||||
|
||||
var collectionName = doc.ns.substr(dbName.length + 1);
|
||||
|
||||
// Is it a special command and the collection name is hidden somewhere in
|
||||
// operator?
|
||||
if (collectionName === "$cmd")
|
||||
collectionName = doc.o.drop;
|
||||
|
||||
_.each(callbacksByCollection[collectionName], function (callback) {
|
||||
callback(EJSON.clone(doc));
|
||||
});
|
||||
|
||||
@@ -14,6 +14,9 @@ var idForOp = function (op) {
|
||||
return op.o._id;
|
||||
else if (op.op === 'u')
|
||||
return op.o2._id;
|
||||
else if (op.op === 'c')
|
||||
throw Error("Operator 'c' doesn't supply an object with id: " +
|
||||
EJSON.stringify(op));
|
||||
else
|
||||
throw Error("Unknown op: " + EJSON.stringify(op));
|
||||
};
|
||||
@@ -192,7 +195,17 @@ MongoConnection.prototype._observeChangesWithOplog = function (
|
||||
|
||||
var oplogEntryHandle = self._oplogHandle.onOplogEntry(
|
||||
cursorDescription.collectionName, function (op) {
|
||||
oplogEntryHandlers[phase](op);
|
||||
if (op.op === 'c') {
|
||||
// If it is not db.collection.drop(), ignore it
|
||||
if (op.o && _.isEqual(_.keys(op.o), ['drop'])) {
|
||||
published.each(function (fields, id) {
|
||||
remove(id);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// All other operators should be handled depending on phase
|
||||
oplogEntryHandlers[phase](op);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user