Announcement Announcement Module
Collapse
No announcement yet.
Queries using DBRefs Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Queries using DBRefs

    I have a simple class Foobar that contains a list of Objects that have a name.
    These are stored using DBRefs.

    What i wanna do is search for Foobars where one of these objects name is something.

    JSON of Foobar looks like this:

    Code:
    {
      "_id": ObjectId("4dc01b367064d7e9b6418e68"),
      "refs": [
        {
          "$ref": "camelCaseClass",
          "$id": ObjectId("4dc01b367064d7e9b4418e68")
        },
        {
          "$ref": "camelCaseClass",
          "$id": ObjectId("4dc01b367064d7e9b5418e68")
        }
      ]
    }
    This does not work (of course)

    Code:
    		Query query = new Query();
    		query.addCriteria(Criteria.where("refs.name").is("foo1"));
    		
    		System.out.println(query.getQueryObject().toString());
    		
    		List<Foobar> find = template.find("foobar", query, Foobar.class);
    But this doesn't work as well:

    Code:
    		query.addCriteria(Criteria.where("refs.$id").is(foo1.getId()));
    (Doesn't work means i don't get the expected result, i get an empty list)

    Is it even possible to query across documents using DBRefs?
    Do i have to store them embedded if i want to be able to do so?

    Thanks

  • #2
    I don't understand. Would you rephrase the question please?
    In your example, all ObjectIds are the same. It's like having an object with attributes objects pointing to themselves.

    Do you mind posting the Java code?

    Comment


    • #3
      http://ethone.de/spring/mongodb-samples.zip

      look @ DBRefTestCase

      Comment

      Working...
      X