Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SpringMongo Case insensitive search regex
  2. Query query = new Query( Criteria.where(propName).regex(value.toString(), "i"));
  3.        
  4. > db.foo.insert({name: "Bill"});
  5. > db.foo.insert({name: "Bill status"});
  6. > db.foo.insert({name: "another Bill"});
  7. > db.foo.find()
  8. { "_id" : ObjectId("5018e182a499db774b92bf25"), "name" : "Bill" }
  9. { "_id" : ObjectId("5018e191a499db774b92bf26"), "name" : "Bill status" }
  10. { "_id" : ObjectId("5018e19ba499db774b92bf27"), "name" : "another Bill" }
  11. > db.foo.find({name: /bill/i})
  12. { "_id" : ObjectId("5018e182a499db774b92bf25"), "name" : "Bill" }
  13. { "_id" : ObjectId("5018e191a499db774b92bf26"), "name" : "Bill status" }
  14. { "_id" : ObjectId("5018e19ba499db774b92bf27"), "name" : "another Bill" }
  15. > db.foo.find({name: /^bill$/i})
  16. { "_id" : ObjectId("5018e182a499db774b92bf25"), "name" : "Bill" }