extra quotes around the regular expression are creating problem. Can someone help me out in this?
Hi Satyam,
To use the $not operator in combination with the $regex operator via a driver interface, you would have to utilise the language’s regex capability to create a regex object. For example, in Java you can use java.util.regex.Pattern.
import java.util.regex.Pattern;
import static com.mongodb.client.model.Filters.not;
import static com.mongodb.client.model.Filters.regex;
Pattern re_pattern = Pattern.compile(".*golf.*", Pattern.CASE_INSENSITIVE);
MongoCursor<Document> cursor = collection.find(not(regex("PostText", re_pattern)));
The snippet above was tested using MongoDB v3.2.8 and mongo-java-driver v3.3
Best regards,
Wan.