How To Use TypeORM with MongoDB?

Hi, I am trying to use typeorm to create database migrations for mongo.

It seems to work for me with every other database, but not mongo. No migrations are ever generated, and I always get the error:

No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" command


I have asked about this in multiple places but have not received any answers:

Appreciate any help. :pray:

Thanks! :heart:

bump :upside_down_face:

anyone have any thoughts on this?

…:cricket::cricket::cricket: :upside_down_face:

Hi @James_Lynch,

Welcome to the MongoDB Community!

Unfortunately there don’t appear to be a lot of users with experience using TypeORM with MongoDB, but it does look like you’ve asked in all of the right places to try to reach relevant audiences. Thanks for including the other links here – that will be useful for anyone else with a similar question.

I see that you have received at least one answer on your Stack Overflow question (although it looks like it took a +50 bounty to encourage responses). It seems that TypeORM currently ignores creating migrations for MongoDB, and the suggestion was to use a standalone migration tool instead.

MongoDB does not have a fixed schema or catalog to reference, and there is no strict requirement for all documents in a collection to have identical schema. You can enforce optional schema validation on inserts and updates using JSON Schema validation, but changes in schema validation rules do not affecting existing documents.

For larger deployments flexible schema can have significant performance benefits: you can change schema (or schema validation rules) without immediately rewriting all of the historical documents. However, the onus of handling schema variations is then pushed down to your application code.

If your use case requires a strictly consistent schema for all documents, you can still create more traditional migration scripts. However, there is some potential flexibility in choosing how to migrate documents. For example, you could choose to migrate documents in batches (perhaps based on some criteria like newest to oldest created) in order to control the impact on your MongoDB deployment’s working set or performance.


1 Like