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 :
def venues = Venue.findAllByTag("def");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.