I’m experimenting with Mongo Transactions. Locally, everything works great. When I push to production, my publication is not picking up the change – in this case a newly inserted doc. When I do a .find.fetchAsync
after the insert, I see the document there but when I observeChanges
on the publication, the added
is never triggered so even though the document is in the database, the client never receives the document.
I’m using the free Mongo Atlas tier and I’ve configured the MONGO_OPLOG_URL
. I see the using oplog
in Monti APM when I call the Meteor Method to insert the document via a Transaction. I’ve tried various things with no luck.
Any ideas? Has anyone been able to get this to work in production?
I’m using Meteor 2.14
// settings.json
{
"galaxy.meteor.com": {
"env": {
"MONGO_URL": "mongodb+srv://xxx:yyy@cluster0.fq1piue.mongodb.net/mainDB?retryWrites=true&w=majority&ssl=true",
"MONGO_OPLOG_URL": "mongodb+srv://oplog:yyy@cluster0.fq1piue.mongodb.net/local?authSource=admin&ssl=true"
}
},
"monti": {
"appId": "xxx",
"appSecret": "xxx"
}
}
// /server/main.js
import { Meteor } from 'meteor/meteor';
import { Links } from '/imports/api/links';
import { MongoInternals } from 'meteor/mongo';
import { Random } from 'meteor/random';
Meteor.publish('links.all', function() {
const cursor = Links.find();
cursor.observeChanges({
added(id, link) {
// in production, this isn't triggered
console.log('link added', id, link)
}
})
return cursor;
});
// Method
const insertLinkWithTransaction = async () => {
const { client } = MongoInternals.defaultRemoteCollectionDriver().mongo;
const session = client.startSession();
try {
await session.withTransaction(async() => {
return await Links.rawCollection().insertOne({ _id: Random.id(), title: 'hello' }, { session });
})
// I see the newly inserted link when I console log here
console.log('links after transaction', await Links.find({}).fetchAsync())
return;
} finally {
await session.endSession();
}
}
Meteor.methods({ insertLinkWithTransaction })