json-api-dotnet / JsonApiDotNetCore.MongoDb

MongoDB support for JsonApiDotNetCore.
https://www.jsonapi.net
MIT License
14 stars 9 forks source link

Support for filtering, projecting and sorting of nested fields #76

Open craigedmunds opened 1 month ago

craigedmunds commented 1 month ago

We want to be able to support sorting, paging & filtering of nested documents.

So given “transactions” records like

{
    user : {
      name : string, dob:date
    },
    created: date,
    amount: int
}}

You should be able to query things like: ?sort=user.name ?fields[transaction]=user.name ?filter[user.name][eq]=whatever

We’ve considered using a different framework, and are happy to contribute if a design is agreed.

bkoelman commented 1 month ago

Yes, something like that would be great to have. To implement that, the ResourceGraph first needs to be extended to support these inline/complex properties, which is also required for https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1439. Then query string parsers can validate input against the resource graph. Then query translation needs to be extended to emit LINQ expressions for them.

I suspect it can be done with EF Core, just haven't investigated it deeply yet. I don't know if the MongoDB LINQ provider can handle such queries (but the answer is likely yes).

Some experimentation, followed by a working prototype, would help to discover how to best design this. For example, we could inherit from AttrAttribute or from ResourceFieldAttribute, or enhance the existing AttrAttribute. This depends on their usages throughout the codebase, what information is needed where, etc.

bkoelman commented 2 days ago

@craigedmunds Are you still interested in contributing to achieve this?