Open jkears opened 2 years ago
I included the definition of the ModelReference (child collection).
@PascalSenn , I was told you are the maintainer of the MongoDB integration library. Please see the above issue and let me know if you require further information.
Is filtering of children not possible in the MongoDB integration?
If yes and you can't provide me with an answer, can you at least provide me with hints as to where to look within the MongoDB integration source code so that I can try to figure this out. This is a major issue for us at the present time.
Thank you in advance, John
@jkears at the moment this is not possible. How would the mongo query look like if you would issue one? Also, do you mind filtering in memory? this would be possbile.
@PascalSenn , thanks for your prompt reply. I thought we were doing something wrong.
Yes, filtering in memory would be fine for most of our scenarios, how would I integrate this via a GraphQL query?
@PascalSenn, this seems to be the way that you'd filter it.
@jkears okok. so opting for the aggregation pipeline.. i mean, could work. Has other issues of course ;) like scalability of queries. But depending on the document you receive this might not even be necessary.
so try this
services.AddMongoDbFiltering(); //ordermatters
services.AddFiltering("queryable")
and then do
[HotChocolate.Data.UseFiltering("queryable")]
[HotChocolate.Data.UseSorting]
public List<GatewayServicesGatewayDefinitionSM.ModelReference> ModelReferences { get; set; } = new();
@PascalSenn
I swear I was able to add a string previously, but now I get this error ..
error CS1503: Argument 1: cannot convert from 'string' to 'System.Type?'
Here are my package references...
mybad [UseFiltering(Scope = "queryable")]
@PascalSenn Yes I had also figure that I needed to define scope.
I also have to change this to
.AddMongoDbFiltering()
.AddFiltering("queryable")
to this ..'
.AddMongoDbFiltering("queryable")
.AddFiltering()
as when it was complaining that it was missing AddFiltering()
However, now it is complaining ...
_1. The name gatewayServices_modelReferenceFilterInput
was already registered by another type. (HotChocolate.Data.Filters.FilterInputType
@PascalSenn I am still not getting this to work...
As mentioned, when I attempted to configure filtering this way....
.AddMongoDbFiltering()
.AddFiltering("queryable")
I get this exception at startup ...
[nextwarecoreservicesgatewayservices_825fad40-c]: 1. No default filter convention found. Call `AddFiltering()` on the schema builder.
[nextwarecoreservicesgatewayservices_825fad40-c]: (HotChocolate.Types.ObjectType<NextWare.CoreServices.SharedModels.GatewayServices.GatewayDefinitionAggregate.Models.GatewayDefinition>)
and if I try it this way ...
.AddMongoDbFiltering("queryable")
.AddFiltering()
I get this exception at startup...
1. The name gatewayServices_modelReferenceFilterInput was already registered by another type. (HotChocolate.Data.Filters.FilterInputType<NextWare.CoreServices.SharedModels.GatewayServices.GatewayDefinitionAggregate.Models.ModelReference>)
We are desperately trying to get this working, can you please advise what it is I am doing incorrectly? Many thanks!
@PascalSenn , can you please help me resolve this issue?
Exact same issue as @jkears . Is there a fix? I couldn't get it working even as much as https://github.com/ChilliCream/graphql-platform/issues/5622 describes.
Following the callout: https://chilly-relay-docs.netlify.app/docs/hotchocolate/v11/integrations/mongodb/#filtering
My ServiceCollection.cs has this:
.AddMongoDbFiltering("queryable")
.AddMongoDbSorting()
.AddMongoDbProjections()
.UseDefaultPipeline()
.AddFiltering()
.AddSorting()
My query has this:
[UsePaging]
[UseFiltering(Scope ="queryable")]
[UseSorting]
[Authorize(Policy = Policy.Name.LicensedUsersOnly)]
[GraphQLDescription("Get all sites")]
public async Task<IEnumerable<Site?>> GetSitesAsync()
Additionally I injected the IResolverContext to the query and attempted to filter like this:
var result = sites.Filter(context)
where context is the IResolverContext. It throws an exception here: Filtering was not found. Register filtering with [UseFiltering] or descriptor.UseFiltering()
. If I remove the Scope from [UseFiltering], there is no error, but obviously the filter is not attempted.
@parihatch
The issue that @jkears had was that the mongodb filtering was picked up when in memory filtering should have been used.
So in your example you should actually register it differently:
.AddMongoDbFiltering()
.AddMongoDbSorting()
.AddMongoDbProjections()
.UseDefaultPipeline()
.AddFiltering("queryable")
.AddSorting()
Then you can annotate queryable
on the field that you want to filter in memory.
This only works for queryables btw:
var result = sites.Filter(context)
Is there an existing issue for this?
Describe the bug
I have a simple document that has a collection (modelReferences), and within it that I would like to filter the modelReferences by their Id property, however filtering at these child collections does not appear to work.
Note: When the exact same model is configured with the EFCore integration it works as expected, but not using MongoDb integratation.
Here is a simple example, of an unfiltered query on modelReferences child collection:
Resultant data :
And with the filter in which the id does not exist:"
Should return no data modelReferences collection items, as that ID does not exist, however it returns everything as if is unfiltered:
Here is the GraphQL configuration:
Here is the Query Definition:
Here is the model definition:
Here is the Node Resolver:
Here is the related child type, "ModelRerference" that I am trying to filter:
Steps to reproduce
Relevant log output
No response
Additional Context?
No response
Product
Hot Chocolate
Version
12.8.2