Grails MongoDB索引嵌入式字符串列表

时间:2011-12-27 12:35:00

标签: grails mongodb indexing gorm

我是MongoDb的新手,我有以下问题:

class Venue {   

String name 
List<String> tags

    static mapWith = "mongo"

static mapping = {
    tags index:true     
}


new Venue(name: 'Test1', tags:['abc', 'def']).save()
new Venue(name: 'Test2', tags:['abc', 'ghi']).save()

现在我想查询具有特定标签的场地。

def venues = Venue.getByTag(['def']);

不幸的是,查询不起作用。有更好的方法吗?

现在我知道如何获得具有特定标签的场地:     def venues = Venue.withCriteria {         eq'标签','def'     }

如何发现是否会使用索引?

1 个答案:

答案 0 :(得分:1)

Dynamic finders以“find”开头,而不是“get”。

所以你会写一些类似的东西:

def venues = Venue.findAllByTag("def");
相关问题