Calling named pipeline from Mongoose

While you can save pipelines in MongoDB Compass, I don’t see a way to call them by name using Mongoose, i.e., to avoid having to have the steps hard-coded into the application. Am I missing something?

Thanks in advance.

Hi @Steve_King, welcome to the community!

The pipelines you saved in mongodb compass are restricted to the application. If you want to reuse them though, you can create a view using an aggregation pipeline. a view is a virtual collection (a query) that is computed each time you query/aggregate it. Also you can use it in any database client, including mongoose.

Since the view is a virtual collection, there are some restrictions though, you cannot edit the view’s document since it’s running the saved pipeline each time you query it and therefore there is no documents to edit. Also any index should be added to the original collection.

Cheers :wink: