Closed Didier542 closed 3 years ago
Does using the model or collection cover your use case?
Depending on how you instantiate your dataSource class, you will have access to this.model
or this.collection
which in turn will have all the usual mongo query methods such as findOne
.
Assuming you want to do something like find user by email address, you could do something like this.model.findOne({email: "myemail@example.com"})
Does this cover your use case?
Adding caching & dataloader for queries other than by _id
would be a great feature. A related feature is #1. If you or someone else is interested in working on a PR, happy to discuss which feature makes more sense and the API 🤗
Submitted a PR for this a couple days ago. It's my first real OSS contribution, so I'd love some feedback from anyone willing to review!
I've got a few ideas for making it even better, but I need to finish up some stuff for work.
I see the problem trying to be solved. But I have a completely different view on how it should be done. As it stands now the API doesn't allow for more complex queries and the PR from @RyanG26 doesn't resonate with me.
Ideally the best solution in my opinion is to retain the existing functionality of Mongoose and the MongoDB driver while building the cache and dataloader ontop. I have a rough idea how this could be achieved by wrapping the mongoose model and/or collection with a proxy and caching results based on the query and results.
@Idono87
I see the problem trying to be solved. But I have a completely different view on how it should be done. As it stands now the API doesn't allow for more complex queries and the PR from @RyanG26 doesn't resonate with me.
Ideally the best solution in my opinion is to retain the existing functionality of Mongoose and the MongoDB driver while building the cache and dataloader ontop. I have a rough idea how this could be achieved by wrapping the mongoose model and/or collection with a proxy and caching results based on the query and results.
I'd love to work through this with you. It's been a little while since I was in the codebase so I'm struggling to imagine the solution you're describing, but It sounds pretty neat!
Lmk if you'd like to talk through it with someone!
Idono's suggestion reminds me of #1
In some cases, we need to identifying our entities by reference other than their ids. Like in an e-shop with the upc reference.
For us, its concerns 3/4 of our requests. Its make the datasource mongodb package a bit useless.
The idea is to add 3 api's :
What do you think about it ?