Announcement Announcement Module
Collapse
No announcement yet.
mongodb match Query Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mongodb match Query

    Hi,
    I have just recently started using Spring Document for MongoDB integration. I have been successful in writing few simple queries. I now want to write some queries which does a basic matching like if a company 'name' starts with 'de'. I tried few ways but didn't succeed. Can someone please help me as how to do it.
    I am doing it as below

    Query query = new Query(where("cId").exists(true));
    if (namePattern != null)
    {
    String regex = "/^" + namePattern + "/i"; //where namePattern = "dc"
    query = query.addCriteria(Criteria.where("name").regex(reg ex));

    }
    query.sort().on("name", Order.ASCENDING);
    List<Company> companies = mongoTemplate.find("company", query, Company.class);

    and it didn't quite return matching results

    command line below does return data
    db.company.find({name : /^dc/i});


    I would also like to learn some advance querying with Spring MongoDB, and would be thankful if someone can point me to some examples or docs of some sort.

    Thanks!
    wquamar
Working...
X