Error when trying to use findOneAsync instead of findOne

HI guys, I’m starting the migration following the approach of first migrating to Async in Meteor 2.8
I tested by changing findOne to findOneAsync.

Example:

function async findOne(collection, selector = {}, options = {}){
 collection.findOneAsync(selector, options)
}

function async getDocument(collection){
const document = await collection.findOne(collection)
}

When calling getDocument I get:

(node:66702) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION] [ERR_ASSERTION]: Cannot await without a Fiber

Have you encountered this issue before or any ideas of how to handle it?
Thanks!

function async getDocument(selector){
   const document = await collection.findOneAsync(selector)
}

You should use findOneAsync instead, and ensure you pass a selector in, not a collection as first argument.

Meteor compiles async functions so they always run in a fiber. Does you app or package have a dependency on the ecmascript package?

Yes it does. Does it affect? :open_mouth:

Sometimes the error is caused by not using the ecmascript package.

1 Like