It's pronounced Diane. I do data architecture, operations, and backend development. In my spare time I maintain Massive.js, a data mapper for Node.js and PostgreSQL.
The catch here is that you're hitting the database as many times as you have matching users, plus the query to find the matching users in the first place. It doesn't hurt much at smaller scales but it'll quickly grind things to a halt once you have more data.
I know Mongo has update with multi or updateMany which could improve matters, although I don't know if Mongoose has different idioms. But honestly, my first recommendation here is to reevaluate Mongo. The portion of your data model shown here is purely relational, and you're having to crudely approximate relational database features to do what you want. Why not just use a relational database?
Thanks for the comment, Dian. I really appreciate it. Yes, normally I would use a relational database for this kind of application due to the relationships between the models. SQL gives you cascades and much more right out of the box.I just wanted to experiment on how cascades could be achieved using mongoose :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The catch here is that you're hitting the database as many times as you have matching users, plus the query to find the matching users in the first place. It doesn't hurt much at smaller scales but it'll quickly grind things to a halt once you have more data.
I know Mongo has
update
withmulti
orupdateMany
which could improve matters, although I don't know if Mongoose has different idioms. But honestly, my first recommendation here is to reevaluate Mongo. The portion of your data model shown here is purely relational, and you're having to crudely approximate relational database features to do what you want. Why not just use a relational database?Thanks for the comment, Dian. I really appreciate it. Yes, normally I would use a relational database for this kind of application due to the relationships between the models. SQL gives you cascades and much more right out of the box.I just wanted to experiment on how cascades could be achieved using mongoose :)