Marking field as populated manually? #2075

Closed
inca opened this Issue May 14, 2014 · 8 comments

Projects

None yet

4 participants

@inca
inca commented May 14, 2014

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.

Is it possible to avoid this casting somehow? Or marking the group as it was populated?

@lazutkin

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

@vkarpov15
Collaborator

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.

@inca
inca commented May 17, 2014

Thank you for your kind feedback! Looking forward to see this super awesome ODM fly up to the 4.0.

@vkarpov15 vkarpov15 added this to the 4.0 milestone May 19, 2014
@vkarpov15 vkarpov15 closed this Dec 5, 2014
@mathieug

Is this now possible?

@vkarpov15
Collaborator

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[2] = member; will leave members[2] as an ObjectId.

@mathieug

Thank you. Is there a documentation?

@vkarpov15
Collaborator

Not yet, see #2884 to track.

@mathieug

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment