简体   繁体   中英

Remove quotes from MongoTemplate query with $in clause

I have mongoTemplate query with a combination of various criterias. In this query I need to select documents by a collection of Ids. So I use "in" method.

Here is my code:

Query query = new Query(Criteria.where("sizeId").is(sizeId));

query.addCriteria(Criteria.where("companyId").in(companyIds));

List<StatisticUnit> result = mongoTemplate.find(query, StatisticUnit.class);

"companyIds" is a List of Integer values.

I've got no result because MongoTemplate wraps $in operator arguments in qoutes so that Mongo consider them as Strings. Real query looks like this:

$in: ["5", "15"]

instead of

$in: [5, 15]

How to tell mongoTemplate not to ignore a type of collection values and not to wrap them in quotes in case of Integer? Thanks!

I solved this issue by myself. When I use HashSet instead of ArrayList everything goes ok. Hope this helps someone else.

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