Closed mikeckennedy closed 1 year ago
Hi Michael, Sorry for the delay. On it
The first problem I think I'm not able to solve nicely is that Release
is a BaseModel class, which is not patched to call arguments on the class (non-instance) level and the magic methods (like eq) for it are also not patched.
I see two ways to solve this:
Embedded
that will support the syntax like Release.major_ver==7
. But you will have to use it instead of BaseModel: class Release(beanie.Embedded):
ElemMatch(Package.releases, major_ver=7, minor_ver=1, build_ver=0)
I think the first option is better, as the syntax is more consistent there.
@mikeckennedy What do you think?
Hey @roman-right Thanks for thinking about this one. Both are interesting solutions.
As for having an EmbeddedDoc base class, I think I’d be fine with that. MongoEngine has something similar. On one hand, I think it would lead to a more consistent API. But I don’t know how much trouble/work it’ll cause for the larger codebase.
The second way looks good to me too. Although, at that point, it’s not adding much value beyond the dictionary variation I put in the description of issue.
So I guess my thoughts are if you’re 100% behind beanie.Embedded
, that’s cool. But otherwise, maybe just close and tell me to use the dictionary version I’m already using. ;)
Hi @roman-right sorry if issue isn't the right format for this. Feel free to close it if you think it doesn't belong...
ElemMatch
currently supports matching on a flat list, such as:But for work I'm doing, we have a list of embedded documents which is one of the primary reasons to use
elemMatch
.Then I want all packages with a certain version, say 7.1.0. I can do that like this now:
But I think ElemMatch should support some way to do this without falling back to raw dictionaries (so things like "find usages" and refactoring work):
You could even keep it with dictionaries such as: