javamongodbdbobject

how to take a single record from an arraylist in mongodb


I am working with mongodb, and i have a pojo class named "Search"

        @Document(collection = "search_details")
        public class Search {

        @Id
        private String id;
        private String searchkey;
        private ArrayList<Lead> leads;
        private String status;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public ArrayList<Lead> getLeads() {
            return leads;
        }

        public void setLeads(ArrayList<Lead> leads) {
            this.leads = leads;
        }

    }

and the Lead class looks like this...

private String id;
private String title;

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

i have some data in my database containing one search form with mulitiple lead forms. I have to take a single lead form form my database. Please help me for finding a better solution for this. Thank you.


Solution

  • Perhaps this can help.

    Query query = new Query().addCriteria(Criteria.where("searchkey").is("test").and("status").is("status").and("leads.title").is("title"));
    query.fields().include("leads.$");