New Meteor 2.8 and the new MongoDB Async API


I hope you all are doing well. Meteor 2.8 brings updates on Node to 14.21, which introduced security updates. You can see the details, security notes, the new MongoDB Async API, the update on MongoDB Driver to 4.9 , addition of the new skeletons for Solid and Chakra-UI and the Meteor.callAsync method.On our road to a Fibers-free Meteor, we continue to make upgrades, as seen in our changelog. Today, I will highlight the new feature and also give an example of how to already start using MongoDB Async API.Before jumping to the highlights, I would point out that is extremely important to look with attention at the migration guide for 2.8Meteor.callAsyncNow Meteor.call() should be called for methods that run sync stubs. For methods that run async stubs, you should use Meteor.callAsync().But be aware that right now, this new method has limitations, and before you start using it, you should read our migration guide. There, we go over these limitations and everything you should know about them.New MongoDB APIWe have added those well know and loved methods to their async counterpart, as you can see from this list:Newly added collection methods:

  • createCappedCollectionAsync
  • createIndexAsync
  • dropCollectionAsync
  • dropIndexAsync
  • findOneAsync
  • insertAsync
  • removeAsync
  • updateAsync
  • upsertAsync

And for cursor methods:

  • countAsync
  • fetchAsync
  • forEachAsync
  • mapAsync

and also, we've added [Symbol.asyncIterator] that can be used like this:for await (const document of collection.find(query, options)) /* ... */How can I use them?You do not need to upgrade your methods right now and can continue to use your code even when updating to 2.8. These methods were just an addition to the current API.You can follow with this simple snippet taken from the changelog:// Before 2.8, we would use something like thisexport const removeByID = ({ id }) => { SomeCollection.remove({ _id: id });};// Now we can also do like thisexport const removeByIDAsync = async ({ id }) => { await SomeCollection.removeAsync({ _id: id });};Meteor.methods({ removeByID, removeByIDAsync,});// In UI use Meteor.call('removeByID', { id }) or Meteor.callAsync('removeByIDAsync', { id })We've made it possible to use async await within MongoDB API calls.Other notable changesSkeletons UpdatedWe have already updated our skeletons to use the newest mongo versions.Big thanks to:

New SkeletonsWe as well have added two new skeletons:

  • For Chakra-UI that can be created using --chakra--ui
  • For SolidJs that can be created using --solid

If you want to try them out, check this doc to see how you can create projects with them in docs.A big thanks to :

  • @Grubba27 for making those Pr's
  • @Akryum for making SolidJS integration possible with Vite

Minimongo & MongoDB FixesWe have solved some issues you could have encountered and made some solutions even better. Big thanks to @radekmie for his PRsMongo:

  • Improved oplogV2V1Converter implementation. PR.
  • Exit on MongoDB connection error. PR.
  • Fixed MongoConnection._onFailover hook. PR.
  • Fixed handling objects in oplogV2V1Converter. PR.

Minimongo:

  • Solved invalid dates in Minimongo Matcher PR.

Readme Visual ReworkAlso, thanks to @victoriaquasar, who has made this excellent PR reworking the Readme of Meteor to match this new and modern vision we are walking towards.Updatingif you liked what you saw, you could update by following these steps:If you are in 2.7.3cd your-projectmeteor updateAny other versioncd your-projectmeteor update --release 2.8Again, please do not forget to check out the migration guide for a full understanding of the changesNotable mentionsI thank all contributors who have worked hard to make this release possible with issues, discussions, and PRs.And a big and warm hug to these contributors in particular that I have not mentioned yet:

Appreciate the work that you all did to make this great framework even better!New Meteor 2.8 and the new MongoDB Async API was originally published in Meteor Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.