Can you query based on a referred document? #5889
Unanswered
AlvesJorge
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hello @AlvesJorge -- Mongoid does not currently support this style of query; you would need to split it into two queries currently (one to fetch the matching band ids, and the other to find the Award documents for those bands, as you've done in your workaround). If you're using the driver directly, you can do this with an aggregation pipeline with a '$lookup' stage. We plan to add a aggregation pipeline builder DSL to Mongoid "soon", which could likely become a foundation for a feature like what you're describing. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Going with the example schema:
I know that if Band embedded Award I could simply query
But if Band only refers to award how could I perform a similar query?
This doesn't work:
Is there a method that would allow for band to be populated for query purposes?
Something like:
Using
aggregate
returns BSON documents, which I don't love.Embedding awards would stop me from querying for awards directly, which I don't want.
I created an abstraction for this purpose, but I don't love it either, since it requires the knowledge of it's existence.
Which I then call like so
TL;DR: Is there a method to allow for querying for refered associations as if they are embedded? :)
PS: I realize that this question may be more geared towards the mongo ruby gem :)
Beta Was this translation helpful? Give feedback.
All reactions