Changing an objects model on the fly through an external plugin

123 views
Skip to first unread message

Lior Kesos

unread,
Sep 1, 2014, 9:11:18 AM9/1/14
to mongoo...@googlegroups.com, Yonatan Ellman
We use (and love) mongoose in mean.io .
We recently launched the ability to create "fullstack packages" which provide both client side code (angular directives, services, controllers, css) and server side (express routes, mongoose defined models etc.)
Take for account the next scenario - I created a google maps package which has a map and location picker directives.
We have an existing model called articles demonstrating basic crud functionality with mean.io.
I want the google map package to inject and alter the articles model and add a:
location -> lat/lng to the existing articles schema.
How can this be achieved? Does mongoose have some kind of hook to alter a schema on runtime?
Lior

Jason Crawford

unread,
Sep 1, 2014, 12:34:31 PM9/1/14
to mongoo...@googlegroups.com, Yonatan Ellman
Yeah, I think you can just use schema.add({…}) for this:


-Jason

--
Blog: http://blog.jasoncrawford.org  |  Twitter: @jasoncrawford




--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Valeri Karpov

unread,
Sep 9, 2014, 1:32:25 PM9/9/14
to mongoo...@googlegroups.com, yon...@linnovate.net
Hi Lior,

Glad to see mean.io is chugging along. This looks super cool! Mongoose doesn't support modifying a Model's schema after its been compiled - you'd have to do that at server start, before actually compiling the model.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe@googlegroups.com.

Nasiruddin Saiyed

unread,
Jul 28, 2017, 6:26:39 AM7/28/17
to Mongoose Node.JS ODM, yon...@linnovate.net
how to do it ? 
Hi Lior,

To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages