1

I have 2 entities as following:

@Document
public class Freelancer {
 @Id
 String id;
 String name;
 @DbRef
 List<Project> bidProjects;
}

@Document
public class Project {
 @Id
 String id;
 String name;
}

Project can't have the ref to freelancer as there could be many freelancers who can bid the projects. I want do following:

Find the freelancer who has placed a bid on project with name = "XYZ".

What should be the query (JSON based Query) for this, i tried following (other combinations but nothing works):

@Query("{ 'completedProject': {'$ref': 'project', 'name': ?0 } }")
@Query("{ 'completedProjects': {'$ref': 'project', 'name': ?0 } }")
@Query("{ 'completedProject': [{'$ref': 'project', 'name': ?0 }] }")
Rakesh Sinha
  • 19
  • 1
  • 6

1 Answers1

1

{ 'fieldName': {'$ref': 'collectionName', '$field': { '$ofield' : ?0 } } }

so it would be

@Query("{ 'bidProjects': {'$ref': 'project', '$name': { '$oname' : ?0 } } }")

imgr8
  • 501
  • 4
  • 11
  • 25
  • I tried it and it never worked for me. What does "$ofield" represent, is it the name of the field, we are already providing it. – Rakesh Sinha Jun 14 '13 at 09:12