I’m new to MongoDb and I have following question:
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()
Now I wanna query for Venues with a particular tag.
def venues = Venue.getByTag(['def']);
Unfortunately the query does not work. Is there a better approach?
Now I know how to get the venues with a particular tag:
def venues = Venue.withCriteria {
eq ‘tags’, ‘def’
}
How can I discover if the index will be used?
Dynamic finders start with “find”, not “get”.
So you whould write something like :