Results 1 to 2 of 2

Thread: Regular expression | Mongodb help required

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Posts
    8

    Default 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. #2
    Join Date
    Oct 2006
    Posts
    8

    Default Updated with solution

    Quote 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 +".*")

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •