java - Mongo can't find document while using regex with backslash and & character -


i'm using java mongo find document in database. i'm using following code:

criteria.where(fieldname).regex("astronomy \& astrophysics", "i") 

this string "astronomy \& astrophysics" changed in query to:

astronomy \\& astrophysics 

there documents in database have fieldname fields equal to:

 astronomy \& astrophysics 

but document isn't returned

what java code should use make code work?

for work have escape backslash \

your new code should this

criteria.where(fieldname).regex("astronomy \\& astrophysics", "i") 

see demo here https://regex101.com/r/uj0vd4/11


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -