Let's say I have group and member documents, member was just created and group was fetched earlier.
After member.group = group the member.group becomes ObjectId instead of document. The problem is that I need to use some virtuals, which, in turn, require full document, not just its id. Population works perfectly (awesome stuff, btw, thank you!), but the query is totally redundant as I already have that group.
member.group = group
Is it possible to avoid this casting somehow? Or marking the group as it was populated?
+1 Vote to implement this feature if it is not available for now, since it is really needed when writing unit-tests for models that use ref-s to other models.
This is something that's on the list for mongoose 4.0. Right now, there's no good way to populate manually as far as I know.
Thank you for your kind feedback! Looking forward to see this super awesome ODM fly up to the 4.0.
Is this now possible?
Yep in 4.0.1 you can do this for single populated subdocs (but not document arrays). For instance, OP's members.group = group; will make the group field into a populated doc, but group.members = member; will leave members as an ObjectId.
members.group = group;
group.members = member;
Thank you. Is there a documentation?
Not yet, see #2884 to track.
docs; manually populating fields (Fix #2075)