DEV Community

pomyo
pomyo

Posted on

Similarities of Sequelize.js and Mongoose.js

Choosing the right ORM to play nice with your database is important. It can save you tons of effort when trying to persist your data correctly and efficiently. With the emergence of NoSql databases like MongoDB, popular ORMs like Mongoose helps bridge the gap between your frontend and backend data while traditional relational databases like MySql make great use of Sequelize.

Although MySql and MongoDB are very different databases, the ORMs that support them by creating, finding, updating and deleting data are very similar if not the same.

Here are some ways they look the very similar.

For finding or selecting data, Mongoose and Sequelize both use .find() functions. To return everything in the table Mongoose uses .find({}) while Sequelize uses .findAll({}). To find by the primary key or the id, Mongoose uses .findById() and Sequelize uses .findByPk().

For creating documents or rows, Mongoose and Sequelize both uses the same .create() function to either generate new documents or add new rows to the table. Both have functions to send multiple inserts into their respective databases via .bulkWrite() for Mongoose and .bulkCreate() for Sequelize. Mongoose also have addition ways to create collections via .createCollection().

To update data, both ORMs provide a .update() function with a slight difference where Sequelize declares it's own .upsert() (insert instead if can't find anything to update) function while in Mongoose, an option can be specified on .update(). Mongoose in turn also have several variety of update functions like .updateMany() and .updateOne().

And finally, to delete things, Sequelize offer the mighty .destroy() function while Mongoose uses .delete()(originally also .destroy()). Mongoose can also .deleteOne() and .deleteMany().

Top comments (0)