Reputation: 2928
I'm sure it must be a simple solution but I cannot find it. I have a grails project with a MongoDb database. I want to do a find operation. Using mongo shell I have:
> db.event.find({'author.id':'22'})
But I cannot the same thing inside my grails project. I have tried something like:
Event.find(['author.id':'22'])
and it gives me no results. I must do something the wrong way. My Event domain object has a
Map author
This is my event collection (a part of it)
"_id" : NumberLong(140),
"author" : {
"id" : "22",
"realName" : "toto",
"username" : "rrr"
},
"dateCreated" : ISODate("2014-04-08T20:04:27.054Z"),
Any ideas ?
Thanks. C.C.
Upvotes: 1
Views: 219
Reputation: 105
How i have asked Grails generate "findBy..." into Domain Model, Grails generate "findBy..." methods to fields into domain model.
In you case -
Event.findByAuthor(id)
Upvotes: 0
Reputation: 1376
You can try low-level API (if you're using "mongodb" plugin):
Event.collection.find(['author.id':'22'])
Upvotes: 3