Description
Heiko Scherrer opened DATAMONGO-1151 and commented
Task description
I request a feature that I couldn't find in the current implementation. Probably there's another elegant way to solve the requested behaviour. I need to append all queries to a particular collection with a specific criteria. Think about a multi-tenancy scenario where a discriminator property (holding the tenants name) has to be compared in each query. Doing this within application code is cumbersome and error-prone. IMO this should be applied somewhere deep in the framework, at best near to execution.
Investigation
I had a look at MongoTemplate and implemented a solution with a so called QueryAppender, that is able to add a criteria to a query (for a collection). Unfortunately MongoTemplate uses several alternatives within the finder methods. Some work with Query, others with DBObjects. So before opening Pandoras Box and implementing too many changes within MongoTemplate, I wanted to clarify that my approach might be a solution and no other solution already exists.
Affects: 1.6.2 (Evans SR2)
Issue Links:
-
DATACMNS-293 Add infrastructure for generic query augmentation
("depends on") -
DATAJPA-307 Add support for soft deletes
-
DATAJPA-564 Support for SpEL based parameter expressions in repository query methods
Activity
spring-projects-issues commentedon Jan 30, 2015
Oliver Drotbohm commented
In Spring Data Commons, we're currently investigating what we call a query augmentation engine that provides an SPI to augment (as the name suggests) store interaction of different kinds. As a working prototype we use the scenario of soft-deletes as it's kind of sophisticated as it not only needs query augmentation but complete exchanges of persistence operations (a delete turning into an update etc.). You use case (multi-tenancy) sounds very similar and also closely related to the usage of SpEL to implement security constraints we already support in Spring Data JPA.
Let's assume you'd use the repository abstraction, what kind of mechanism would you prefer to express your custom augmentation? Would - such as in the case of soft deletes - an annotation on the repository work?
spring-projects-issues commentedon Jan 31, 2015
Heiko Scherrer commented
Thanks for clarification. An annotation on Repository level would work for me but I guess many requests will follow - Think about inheritance. An
@Augmentor
(MyImpl.class) would be a good solution on entity class (collection) level.In my initial request I wanted to go for sure that there is no existing solution for my particular use case - seems to be not, but good to hear that it is planned.
SpEL would work for me too, but I'd although have to augment wach query explicitely
spring-projects-issues commentedon Jan 31, 2015
Heiko Scherrer commented
Do you plan a solution for all this in 2.0? I'd like to contribute!
spring-projects-issues commentedon Feb 1, 2015
Heiko Scherrer commented
see comments
arpanpreneur commentedon Jun 27, 2023
Is there any updates on this? Even I need the tenantId based multi-tenancy support. We figured it is too confusing to find a place to append the extra criteria.
Just wanted to understand, does implementing a mongo template also automatically scope the autogenerated queries from arbitrary interface method names?
christophstrobl commentedon Jun 27, 2023
@ArpanKIIT2017 Every repository query will be run by the template, though there's no easy way to work with the
QueryMapper
that is used. Nor is there support for augmenting the query, which is as you already know an open issue in data-commons.