I am using the MongoDB Java client to query data:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.5.0</version>
</dependency>
The server version is 3.4.10.
When using the MongoDB shell, I can successfully query using:
db.c1.find(
{ title: { $in: [/test/,/demo/] } },
{ title:1 }
)
But when using the Java driver it does not work. For example:
List<String> keywords = new ArrayList<>();
keywords.add("/test/");
keywords.add("/demo/");
Document titleRegEx = new Document("$in", keywords);
Document filter = new Document("title", titleRegEx);
Document firstDoc = coll.find(filter).first();
logger.info("firstDoc: {}", firstDoc);
Please help me out.