Question

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.

Was it helpful?

Solution

You can try low-level API (if you're using "mongodb" plugin):

Event.collection.find(['author.id':'22'])

OTHER TIPS

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top