Announcement Announcement Module
Collapse
No announcement yet.
Spring mongodb support: hot to write a like query Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring mongodb support: hot to write a like query

    Hi All

    I'm using Spring 3.1 and Spring mongo support

    I'ld like to have some sample how to write a like query; i'ld like to write, by using the spring Criteria and Query API for mongo, somethink similar to this SQL query:
    Code:
    select * from user where name like '%mart%'
    The bold part is what is interesting for me.....do u have any suggestion? Also fro making it case insensitive

    Thank you so much
    Cheers
    Angelo

  • #2
    Hi there

    I solved this question.
    I used the following code:

    Code:
    Criteria.where("raw").regex(value,"i");
    Where raw is the name of the field where I want to do the like and regex is the Criteria method to use.

    The second parameter ("i") represents the options to pass to the method; in this case "i" tells mongodb to be case insensitive.

    Cheers,
    Angelo

    Comment


    • #3
      Hello Angelo,

      I have a similar concern.

      What is there in the value , does it contains '%mart%'


      Regards,
      Suraj Sharma

      Comment


      • #4
        Hi Suraj

        Nope in the value there is simply the value; for example if you need to search for "%mart%" you have to do:
        Code:
        String value = "mart";
        Criteria.where("raw").regex(value,"i");
        I hope this is useful

        Angelo

        Comment

        Working...
        X