Questions about promises in collection methods

Hey guys,
I’m currently developing a new project and read somewhere, that Meteor will switch over completely to Promises and deprecate Fibers. To maintain my code in the future, I’m wondering if this is true and if there is already a solution to call the collection methods (f.e. find(), update(),…) as Promises? My current idea is to create own methods and use es6-promisify and later change everything to the internal methods when Promises are implemented. Calling the methods via rawCollection and accessing the internal Mongo methods wouldn’t work for me, because I have to use redis-oplog as dependency.

Hey! how are you doing?
Can you elaborate a bit more on that?
On the next release(2.8), we will be releasing async mongo method calls, you can see it better in this Pull Request
is that what you mean, or something like this below (pseudo-js code)?

const findAsyncFoo = 
  (name) => new Promise(r => r(FooCollection.find({ name }).fetch()))
// in the future, this will be findAsync
// using the wrapper?
const data = await findAsyncFoo('bar')

1 Like

thanks for your response. Yes right, great, if the names of the new methods are already available, I should be able to do something like this:


const Sites = new Mongo.Collection("sites");


import {promisify} from "es6-promisify";

function promisifyCollections(col) {

    col.findAsync = promisify(col.find);
    col.insertAsync = promisify(col.insert);

export {promisifyCollections};

And later when it’s implemented into the core, I only have to remove the promisifyCollections(col) call from all collections, right?

Ah, noticed that it only makes sense for the remove or update methods, because find and findOne don’t provide a callback alternative, so I have to use the rawCollection() methods for them.

Hey @XTA. It’ll be enough if you’re sure that you’ll be able to await all collection operations – there’s no need to use promisify. I talked about it on Meteor NYC Meetup (slides; the video is not up yet, @alimgafar?).