Handled implicit collection creation oplog message (fixes #12627).

This commit is contained in:
Radosław Miernik
2023-05-19 13:19:47 +02:00
parent 60f81513fa
commit 6fd3906bc0
2 changed files with 18 additions and 0 deletions

View File

@@ -308,6 +308,9 @@ Object.assign(OplogHandle.prototype, {
trigger.collection = doc.o.drop;
trigger.dropCollection = true;
trigger.id = null;
} else if ("create" in doc.o && "idIndex" in doc.o) {
// A collection got implicitly created within a transaction. There's
// no need to do anything about it.
} else {
throw Error("Unknown command " + EJSON.stringify(doc));
}

View File

@@ -164,6 +164,21 @@ process.env.MONGO_OPLOG_URL && testAsyncMulti(
]
);
import { Mongo, MongoInternals } from 'meteor/mongo';
process.env.MONGO_OPLOG_URL && Tinytest.addAsync(
'mongo-livedata - oplog - x - implicit collection creation',
async test => {
const collection = new Mongo.Collection(`oplog-implicit-${test.runId()}`);
const { client } = MongoInternals.defaultRemoteCollectionDriver().mongo;
test.equal(await collection.find().countAsync(), 0);
await client.withSession(async session => {
await session.withTransaction(async () => {
await collection.rawCollection().insertOne({}, { session });
});
});
test.equal(await collection.find().countAsync(), 1);
},
);
// Meteor.isServer && Tinytest.addAsync(
// "mongo-livedata - oplog - _onFailover",