【问题标题】:grails mongo sort query with key as variable以键为变量的grails mongo排序查询
【发布时间】:2014-01-24 07:33:39
【问题描述】:

我有这个代码(grails):

println sortField
println sortType
domainProfileList = db.getCollection("domainProfile").find(["location.value.city" : ['$in' : location]], ["_id" : 1]).sort([sortField : sortType])

现在这部分有问题:

.sort([sortField : sortType])

key sortField 由 mongo 原样获取(即它呈现为 sortField 而不是 sortField 中存在的值,其中 sortType 呈现为 1 或 -1 )

grails 中实现此目的的正确语法是什么。

【问题讨论】:

    标签: mongodb grails grails-orm grails-2.0


    【解决方案1】:

    请这样使用:

    .sort(["${sortField}" : sortType])
    

    【讨论】:

    • org.codehaus.groovy.runtime.GStringImpl 无法转换为 java.lang.String 出现此错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 2020-10-21
    • 2021-10-29
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多