Procedures in mongoDB

i am working with java with mongodb, earlier we were using postgres sql,
now we are stuck at a problem where we have to convert postgres procedures to mongodb query.
Since mongodb does not have procedures support, is there any alternative for it

i don’t want to put the code inside aggregation pipeline and run it through backend application
i want to handle it from mongoDB only.

Hi Deepanshu, have you had a look at the following docs page on how to use aggregation with the MongoDB Java driver?

1 Like

Hi @Deepanshu_Kumar,

You can find some examples here:

And a blog post about Java + Aggregation Pipelines here:

Depending on what the PostgreSQL procedures were doing, you can replace them with aggregation pipelines or maybe Change Streams can also help for some use cases.

The most important thing when migrating from SQL to MongoDB is to completely rethink the data model.

Relational Migrator can also help for the migration but the data model needs to change for sure.

Cheers,
Maxime.

Just to add to @MaBeuLux88_xxx’s response: Relational Migrator not only helps you convert a relational schema and migrate your data to MongoDB, our new Query Converter feature can automatically convert stored procedures to MongoDB API code.

Query Converter is currently available in private preview, but if you complete the form linked from the product I can grant you access so you can try this.

As you point out, MongoDB does not have stored procedures, so in most cases we would recommend that the migrated code becomes a part of your application’s backend.

1 Like