Skip to content

Conversation

vkarpov15
Copy link

Hi,

Admittedly this is a strange PR, but we've seen instances of people trying to store sequelize objects in MongoDB (like agenda/agenda#562 (comment)). It would be handy if sequelize could implement a toBSON() function so the mongodb driver could automatically serialize it correctly.

Thanks and happy holidays!

Valeri

@sushantdhiman
Copy link
Contributor

You can add a method to model instance, add toBSON on prototype

var Model = Sequelize.define('Model', {
   // various attributes
});

Model.prototype.toBSON = function () {
   return this.toJSON();
}

@vkarpov15
Copy link
Author

I'm aware of that. However, I think it would be handy to have this functionality baked in to sequelize so end users don't have to think about it. Let me know, we can always just write a plugin instead.

@sushantdhiman
Copy link
Contributor

Yeah, its better if this is handled at application code or as a plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants