Announcement Announcement Module
Collapse
No announcement yet.
Regular expression | Mongodb help required Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regular expression | Mongodb help required

    I must be doing something really stupid and need help to realize that . I am using a simple regex like below to find out all matching documents where short name starts with passed name. Now somehow this does not work as i get out of memory because i suspect all documents are getting returned. I tried to put limit in query but that also has not worked .

    results=mongoTemplate.find(Query.query(new Criteria("short_name").regex( "/^" + name +".*/i")), MongoInstrument.class);


    Any insights?

    Thanks

  • #2
    Updated with solution

    Originally posted by Mridul View Post
    I must be doing something really stupid and need help to realize that . I am using a simple regex like below to find out all matching documents where short name starts with passed name. Now somehow this does not work as i get out of memory because i suspect all documents are getting returned. I tried to put limit in query but that also has not worked .

    results=mongoTemplate.find(Query.query(new Criteria("short_name").regex( "/^" + name +".*/i")), MongoInstrument.class);


    Any insights?

    Thanks
    All right, so short answer is don't use "/" because Java does not understand them so this works
    Criteria crt =new Criteria("short_name").regex( "^" + name +".*")

    Comment

    Working...
    X