Results 1 to 3 of 3

Thread: Queries using DBRefs

  1. #1

    Default 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. #2
    Join Date
    Apr 2010
    Posts
    24

    Default

    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?

  3. #3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •