MongoDb: In a many to many relation, when does it make sense to make the ids of both models in the definition of the other model
both approach is correctly I have seen both methods that uses
but when you want to using populate, you should update two collections(users and courses) when you want to insert a new Course
, so you should use transaction because if one was updated and the other did not(An error occurred) rollback be done
the first thing to understand about mongoose population is that it is not magic, but just a convenience method that allows you to retrieve related information without doing it all yourself
if user id
be index
in couresSchema
you can find()
all courses very fast,but the generally recommendation is to consider the data usage patterns of your application and choose what is best