简体   繁体   English

grails mongodb 3.0.2插件使用createCriteria()对关联进行联接查询

[英]grails mongodb 3.0.2 plugin join queries on associations using createCriteria()

I am trying to search for users with particular role using createCriteria().I have three domain classes: User, Role and UserRole (they are from SpringSecurity). 我正在尝试使用createCriteria()搜索具有特定角色的用户。我有三个域类:User,Role和UserRole(它们来自SpringSecurity)。

class UserRole implements Serializable {

    User user
    Role role

    static constraints = {
        user nullbale: false
        role nullable: false
    }

    static mapping = {
        version: false
        id composite: ['role', 'user']
    }
}

I am searching on isActive, name or username fields on User Domain and authority field on Role Domain . 我正在搜索用户域上的isActive,名称或用户名字段以及角色域上的权限字段。

    def c = UserRole.createCriteria()
    def results = c {
        user {
            eq("isActive", true)
            or {
                ilike("name", "somename")
                ilike("username", "someusername")
            }
        }
        role {
            eq("authority", "ROLE_USER")
        }
    }

On running this I get UnsupportedOperationException from mongo plugin. 运行此程序时,我从mongo插件获取UnsupportedOperationException。 Here is stacktrace 这是stacktrace

ERROR errors.GrailsExceptionResolver  - UnsupportedOperationException occurred when processing request: [GET] /users/search - parameters:
query: 
Join queries are not supported by MongoDB. Stacktrace follows:
Message: Join queries are not supported by MongoDB
    Line | Method
->>  162 | handle             in org.grails.datastore.mapping.mongo.query.MongoQuery$2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    142 | handle             in     ''
|   1091 | populateMongoQuery in org.grails.datastore.mapping.mongo.query.MongoQuery
|    993 | executeQuery       in org.grails.datastore.mapping.mongo.query.MongoQuery$58
|    861 | doInDB . . . . . . in     ''
|    833 | doInDB             in     ''
|    542 | list . . . . . . . in org.grails.datastore.mapping.query.Query
|    325 | invokeMethod       in grails.gorm.CriteriaBuilder
|     17 | $tt__searchUsers . in com.themopi.apis.searchactivity.SearchService
|     29 | searchUser         in com.themopi.apis.search.SearchController
|    198 | doFilter . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter           in grails.plugin.cache.web.filter.AbstractFilter
|    106 | processFilterChain in com.odobo.grails.plugin.springsecurity.rest.RestTokenValidationFilter
|     72 | doFilter           in     ''
|     53 | doFilter . . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|   1145 | runWorker          in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                in java.lang.Thread

I found a Jira on this issue but it is unresolved. 我在此问题上找到了一个Jira ,但尚未解决。

Any work around for this till now as jira was created on 09/Mar/12 or I am missing something? 到目前为止,由于jira是在2012年3月9日创建的,因此目前尚无解决方法,或者我错过了一些东西?

I will be using pagination and projections in this query? 我将在此查询中使用分页和投影吗?

Any help or guidance is highly appreciated. 任何帮助或指导都将受到高度赞赏。

Thanks in advance. 提前致谢。

there's an excellent article from Burt on this topic. 伯特(Burt)一篇关于该主题的出色文章

One of the main parts of it is, that the security model should be implemented with embedded/sub-doc entities . 它的主要部分之一是,应使用embedded/sub-doc entities来实现安全模型。 Actually joins shouldn't be used with mongo at all, and if you need those, use a RDBMS or Graph DB. 实际上,联接根本不应该与mongo一起使用,如果需要,请使用RDBMS或Graph DB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM