Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Smahrt/43846ab38288a1497cd61f90a9c9bf38 to your computer and use it in GitHub Desktop.
Save Smahrt/43846ab38288a1497cd61f90a9c9bf38 to your computer and use it in GitHub Desktop.
How to quickly convert mongoose thenable query methods to use .exec()
  • Using any IDE or Code Editor of your choice that supports RegExp for find/replace functions (e.g. VS Code)

  • Paste this in the Find field:

\.(find|findOne|deleteMany|deleteOne|findById|findByIdAndDelete|findByIdAndRemove|findByIdAndUpdate|findOneAndDelete|findOneAndRemove|findOneAndReplace|findOneAndUpdate|replaceOne|updateMany|updateOne)\((.*?)\)
  • Paste this in the replace field:
.$1($2).exec()
  • Click replace all

Note: Ensure to scan through matched files to ensure you are not including any external javascript files or basically files you don't want to include

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment