I figured, when I insert into Mongo, Meteor's Fiber magic waits/blocks until the db acknowledged the write, but not until the observers are called. Is there a way to wait for them?
I'm inserting data in server code, and I have a Caching layer that observes added events on the Collection and casts ObjectModel instances from them:
class CachingService {
attachObservers() {
this.collection.observe({
added: models => this.added(models)
})
}
}
const id = Placements.insert({...})
console.log(`Inserted ${id} -`, CachingServices.Placements.getByID(id), Placements.getByID(id, false))
would print:
Inserted ... - undefined, {...}
i.e. the CachingService didn't receive the insert yet, but the database did.