Support for an Every Operator (like $elemMatch) #1751
Replies: 2 comments 2 replies
-
An update on this. I didn't realize that $elemMatch matched any element. The operation I'm looking for is more like this in MongoDB.
Query Interface OptionsOriginally I was thinking "every" with a subquery makes sense. But after looking into it more, I think something like
Implementation DetailsQuery BuilderI already have a fork of payload where I have the original interface idea working for the multi-select field. It's a little hacked-in right now. After taking an initial pass at this, what makes sense to me to make this more manageable is to add support for arrays in the operator map. So if we said
Then it knows to make this object
GraphQLHonestly, I don't have a lot of experience with Graphql, but I figure implementing something like this is just extending the graphql schema to support another operator. |
Beta Was this translation helpful? Give feedback.
-
Made a PR for a first attempt at this |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Maybe I just can't think of a better way to write this query, but what I'm trying to do is make sure that every element in array is in another array. The best thing I came up with was get the inverse set and use the not_in operator.
Suggested Feature
It would be really nice if we had an every operator. It could be used on array values to make sure all elements match a constraint. I think it would be something like this.
I think this should be an almost direct mapping to $elemMatch in mongodb, but I have never used $elemMatch and I haven't dug into the source code deep enough to see if that is even possible.
Beta Was this translation helpful? Give feedback.
All reactions