Skip to content

feat(model): allow serializing model instances into mongodb#8810

Closed
vkarpov15 wants to merge 1 commit into
sequelize:masterfrom
vkarpov15:patch-1
Closed

feat(model): allow serializing model instances into mongodb#8810
vkarpov15 wants to merge 1 commit into
sequelize:masterfrom
vkarpov15:patch-1

Conversation

@vkarpov15

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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