I am trying to get all documents from my database where the page path ends with a certain expression using this code:
query.put(pagepath, new BasicDBObject(
"$regex", "/(" +expression+ ")$/"));
and where expression is replaced by values like ".html", ".JSON", "contact/", "/"... I get no errors but no results either, even though, when I test my regex on https://regex101.com/ it works and one of the links at least matchs.

expression + "$". Also, you'd need to escape the.somehow. So, perhaps,BasicDBObject query = new BasicDBObject();and thenquery.put(pagepath, Pattern.compile(Pattern.quote(expression)+"$"));{ "\"pagepath\"" : { "$regex" : "\\Q.html\\E$"}}