简体   繁体   中英

Find documents with array that contains a specific value in mongodb using java

According to the answer provided in this link: Find document with array that contains a specific value , i have tried getting the items in java using this statement

searchQuery.put("arrayMine", new BasicDBObject("$in","[xxx]"));
OR
searchQuery.put("arrayMine", new BasicDBObject("$in","xxx"));

But it keeps saying the $in value must be an array while my arrayMine is an array. What should be the correct syntax in java?

Both variants you have are treating the value of BasicDBObject as String .

Use

searchQuery.put("arrayMine", new BasicDBObject("$in",Arrays.asList("xxx"))        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM