Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sample of Projection with MongoDb Provider #39

Open
vinicius-actcon opened this issue May 23, 2022 · 3 comments
Open

Add a sample of Projection with MongoDb Provider #39

vinicius-actcon opened this issue May 23, 2022 · 3 comments

Comments

@vinicius-actcon
Copy link

Hello everyone!

Thanks for became this amazing solution avaliable for the .NET ecosystem.

I"m reading the documentation of "how use HotChocolate with MongoDb at projection level" but I did found any reference of how to use the projection itself.

For exemple, i see that after IMongoCollection we have access to .AsExecutable() extension method and afterwards this execution whe hav access to With options (WithSorting|WithFiltering|WithOptions|WithProjection) and WithProjection method expect an argument of type MongoDbProjectionDefinition, but how can i instantiate this definition?

There's no one reference in nowhere how to create(instantiate) that definition to be used by projection. Could someone provide a sample of how to do that?

Thanks!

@PascalSenn
Copy link
Member

you can just return the executable

[UseProjection]
public IExecutable<Foo> GetFoo(...) => collection.AsExecutable();

Though unless you really have big documents with tons of properties, you may not really see a performance benefit.
Projections are really only a benefit in mongodb when you have covered queries or big documents (and you want to reduce network traffic)
This is a good read:
https://betterprogramming.pub/improve-mongodb-performance-using-projection-c08c38334269

@vinicius-actcon
Copy link
Author

vinicius-actcon commented May 24, 2022

yeah, I'm aware about the performance issues with use of projections, but I really need a projection due to not expose all fields for a given entity.

How could create an "projection" of an entity type with a model type?

@PascalSenn
Copy link
Member

@vinicius-actcon hmm not sure what you mean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants