You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that I can search by id as follows (when I already have the parent document):
parentDoc.children.id()
Now, I want to find by the name somehow as follows:
parentDoc.children.find({name: 'Kinder'})// not a real code, just to demonstrate what I want
You might say, okay it's simple, just call the native JavaScript methods on arrays such as .map, since you're working with an array. That's correct, but I need to run the pre-find middleware I attached to the child schema.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have the following Schema:
where
childSchema
is:I know that I can search by id as follows (when I already have the parent document):
Now, I want to find by the name somehow as follows:
.map
, since you're working with an array. That's correct, but I need to run the pre-find middleware I attached to the child schema.Now, that was the first question, now, :
How about these methods?
Can we work with subdocument arrays just as collections? simply as if they were actually models, we can call all the above methods on them.
I'm sure there's a way to perform all the above, can anyone document this missing part of mongoose?
Beta Was this translation helpful? Give feedback.
All reactions