These are chat archives for Automattic/mongoose

16th
Jan 2017
Paul "Joey" Clark
@joeytwiddle
Jan 16 2017 09:59
@imcodingideas I didn’t see you $push the new gift onto the user’s gift field. That might be why it’s not there!
@realisation If you want the user field to be a document, then you must populate it. Sometimes passing things through JSON will turn an ObjectId into a String.
Paul "Joey" Clark
@joeytwiddle
Jan 16 2017 10:05
@Harpreeit If your User schema references all the different types of document he can own, then you can populate them in one query. (The disadvantage is that this might create double links, if the other documents already reference the user.)
But if there is no link from the User schema, only links back from the other collections to the user _id, then you will have to make a separate lookup query on each collection. :/
hopes he understood at least one of those questions correctly
Markku Virtanen
@cahva
Jan 16 2017 13:08
Hi there! I could not find anything related in github issues so I thought to ask here. Has lean() function changed recently how it works with default values? I'm getting some undefined errors from older objects because schema has changed but with lean() it does not return default values for those anymore. Without lean() it will return the default value if the object does not have it..
Markku Virtanen
@cahva
Jan 16 2017 13:17
I'm just wondering if its intended behavior or is it a bug :)
Paul "Joey" Clark
@joeytwiddle
Jan 16 2017 13:18
@cahva It seems like expected behaviour to me. Using .lean() does less work. It's good for efficiency. But in your case, not good if you want the default values!
Markku Virtanen
@cahva
Jan 16 2017 13:30
yeah I checked with older Mongoose version and it did the same so maybe I remembered wrong. In the future I need to make better migrations and not "lean" on the default values ;)
I usually add lean() everywhere when I don't do any saving or other mongoose stuff to the object anymore. Have to be more careful from now on.
Tobias Lundgren
@lundgren2
Jan 16 2017 16:22
Hi! I wonder if anyone knows how I can find all records in a collection by search for a week number?
Tobias Lundgren
@lundgren2
Jan 16 2017 21:55
Ok, new question: I have store a moment() as a string in my model. But when I try to use find() to return records between two dates, it wouldn’t work with my own stored date. But it works with the “createdAt” timestamp… How can I save the moment so I can use it with my find function? Thanks!
Tobias Lundgren
@lundgren2
Jan 16 2017 22:02
I think I find it! I could use “Date” as type.