Setter for Array Won't Be Called When Modifying

10 views
Skip to first unread message

Wiehwa Cheung

unread,
Jul 29, 2014, 8:49:34 AM7/29/14
to mongoo...@googlegroups.com
I defined a Schema with an String array of emails, and wrote a simple toLowerCase setter for that array.

But I noticed that the setter will be only called when a document is being created, not modifed.

And this fellow's gist could be an example, https://gist.github.com/timoxley/2340936.

I'm wondering why.

Ryan Wheale

unread,
Jul 29, 2014, 5:46:11 PM7/29/14
to mongoo...@googlegroups.com
Sorry if this is stating the obvious - but if you are updating a document, try using the "set" method to invoke the setter method:

doc.set("myArrayField", [...]);
doc.save();

~Ryan


--
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.

Reply all
Reply to author
Forward
0 new messages