Announcement Announcement Module
Collapse
No announcement yet.
Query on @DBREF document Fileds Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query on @DBREF document Fileds

    Hi,

    i have two documents

    Code:
    @Document(collection="ficheprojet")
    public class FicheProjet {
    	//Id Projet Evalue
    	@Id
    	String idProjet;
    	
    	//Projet Evalue
    	String projetEvalue;
    	
    	//Service Gerant le Projet
    	String serviceProjet;
           
            @DBRef
    	private Collaborateur collaborateur;
    
            //getters() and setter()
    }
    referencing

    Code:
    @Document(collection="user")
    public class Collaborateur {
    
         @Id
        private String id;
         
        private String nomCollaborateur;
    
        private String prenomCollaborateur;
               //getters() and setter()
    }

    i'ld extract FicheProjet where nomCollaborateur match a value

    here is my where condition

    Code:
    where("collaborateur.$user.nomCollateur").regex("xxx","i")
    this where doesn't return values

    Please how to fix this issue?,
    Thanks

  • #2
    It can be done by executing two queries:

    Code:
    Query userQuery = new Query(where("nomCollaborateur").regex("xxx", "i")));
    userQuery.fields().include("_id");
    List<Object> userList = mongoTemplate.find(userQuery, Object.class, "user");
    List<String> userIds = resolveUserIds(userList);
    
    Query query = new Query(where("collaborateur.$id").in(userIds));
    List<FicheProjet> list = mongoTemplate.find(query, FicheProjet.class, "ficheprojet");

    Comment


    • #3
      Thanks it helped me to solve my problem tahnks once more

      Comment

      Working...
      X