0

I have a Subscription domain object which has a List of ObjectId as one of its properties, say 'subscribed'. I'm on Grails 2.1.2 and MongoDB.

class Subscription {
    ObjectId id
    List<ObjectId> subscribers = [] as List<ObjectId>

    static mapWith = "mongo"
}

I'm looking for something like this

def c = Subscription.withCriteria {
    contains("subscribers", specificId)
}

Is there a way to do this?

Note: I'm aware of this very same question but provided answer to that question doesn't work for a property which is of type List of ObjectId.

Community
  • 1
  • 1
Nader Ghanbari
  • 4,120
  • 1
  • 23
  • 26

1 Answers1

0

See grails criteria docs. Try to use like this:

def c = Subscription.withCriteria {
    subscribers{
        eq("id",specificId)
    }
}
Mr. Cat
  • 3,522
  • 2
  • 17
  • 26
  • This doesn't work, following runtime error is thrown : Join queries are not supported by MongoDB. Stacktrace follows: Message: Join queries are not supported by MongoDB Line | Method ->> 117 | handle in org.grails.datastore.mapping.mongo.query.MongoQuery$2 – Nader Ghanbari May 20 '13 at 08:38
  • You'd better say that it's mongo before (= – Mr. Cat May 20 '13 at 08:40
  • Sorry about that, I'll edit the question! See my last edit of question in which Subscription class and subscribers property are added. – Nader Ghanbari May 20 '13 at 08:41