The standard behaviour in JS for any method that takes a callback method as the last argument is that it can be easily “promisified” into an async method.
That used to be the way to get async versions for any meteor callback-based method and we also expect that any newly introduced async version of the same method should just be the same as the “promisified” version.
However, for the collection modification methods this is not true when running in the browser (client).
If we have collection modifications blocked on the server, this code will receive an error in the callback (as expected)
We’ve discussed these differences internally and provided documentation to explain them. There might still be some missing details, but here’s a quick overview:
How Mongo Operations Differ: Async vs. Sync
Sync Version/Callback-based: Runs the MongoDB operation in the background via a server method call while simulating the result locally, returning optimistic data immediately.
const id = MyCollection.insert({ field:12 });
console.log(id) // 🧾 Data is available (Optimistic-UI)
// 🔴 Server ended with error (denied insert rule)
MyCollection.findOne({}); // 🗑️ Data is NOT available
Async Version: Runs the MongoDB operation in the background via a server method call, simulates the result locally, and returns promises (stubPromise, serverPromise) for handling the async flow.
const { stubPromise, serverPromise } = MyCollection.insertAsync({ field:12 });
const id = await stubPromise;
// 🔵 Client simulation
MyCollection.findOne({}); // 🧾 Data is available (Optimistic-UI)
console.log(id) // 🧾 Data is available (Optimistic-UI)
try {
await serverPromise;
// 🟢 Server ended with success
} catch(e) {
console.error("Error:", error.reason); // 🔴 Server ended with error
}
MyCollection.findOne({}); // 🗑️ Data is NOT available
The benefits of the sync version are great for many client-side code, since usually handling async as part of your code can produce more complex code. And if you wish to enforce isomorphism as much as possible on client and server you have available the async version.
I haven’t browsed through the entire documentation, but it must be linked on each of the affected functions. For example, I am in a hurry and wanted to know how updsteAsync works. Would the docs about updateAsync tell me about this? (This is just an example)