These are chat archives for Automattic/mongoose

5th
Jan 2017
Michael Lynn
@mrlynn
Jan 05 2017 00:22
Hey - my virtuals just stopped working - can't seem to trace it to a change I've made. I've created a simple virtual to help me with checking equality on a collection...
schema.virtual('isVariable').get(function() { if (this.Product_Group=='DONATION') { return true; } return false; });
Any tips on debugging virtuals?
Michael Lynn
@mrlynn
Jan 05 2017 01:26
virtuals don't seem to work from Express Handlebars... {{#if this.isVariable }} doesn't work... but from node if (this.isVariable) does
Paul "Joey" Clark
@joeytwiddle
Jan 05 2017 01:33
@olsynt Never been in that situation myself, but perhaps this may help: SO stop-mongoose-from-creating-id-property-for-sub-document-array-items
Michael Lynn
@mrlynn
Jan 05 2017 01:35
Hey - I'm wondering if it has something to do with virtuals in combination with Aggregate?
Paul "Joey" Clark
@joeytwiddle
Jan 05 2017 01:37
@mrlynn Quite likely. I think mongoose doesn’t do it’s magic on the results of aggregations, because the result of an aggregation is not always a normal document.
Michael Lynn
@mrlynn
Jan 05 2017 01:38
aha!! @joeytwiddle - thank you... that appears to be it indeed.
thank you!
Paul "Joey" Clark
@joeytwiddle
Jan 05 2017 01:38
YW! (We have also found that you cannot pass Strings and Numbers to aggregations, and expect them to be cast into ObjectIds and Dates respectively, like they are with “normal” mongoose queries.)
Paul "Joey" Clark
@joeytwiddle
Jan 05 2017 01:47
Confirmation of the theory here @mrlynn
If you really want mongoose documents, you could perform a normal mongoose lookup after your aggregation.
But perhaps you can get magic Mongoose documents without another trip to the DB, by simply mapping each of your results through new Document(…)?
Michael Lynn
@mrlynn
Jan 05 2017 01:48
ah - so another closure with a find for that specific doc...
Paul "Joey" Clark
@joeytwiddle
Jan 05 2017 01:48
Yeah :/ But please try the new thing first :)
Michael Lynn
@mrlynn
Jan 05 2017 01:48
ahhhhhhhh - I see... will try - thanks.
Paul "Joey" Clark
@joeytwiddle
Jan 05 2017 01:49
If new Document(…) is given an _id and some fields, then I believe you just have a “checked out” version of the DB document. Saving will only update those fields you modify after creating the object.
Michael Lynn
@mrlynn
Jan 05 2017 01:51
I don't really need to aggregate - I can probably replace the aggregate with a find.
Paul "Joey" Clark
@joeytwiddle
Jan 05 2017 01:51
Oh. Then it’s all much easier. :D
Oleg Sucharevich
@olsynt
Jan 05 2017 08:55
@joeytwiddle , doesnt helped , at the end i just marked the type as mixed and the indexes wont copied.
Raghav Agarwal
@raghav2312_twitter
Jan 05 2017 18:20
hey guys can anybody help me with mongoose save function