'Problem with mongo AddFieldsOperation in java
I have to filter documents by multiple fields using regex (text searching, but mongo text indexes don't allow partial search)
Everything works fine when I make big OR Criteria
Criteria().orOperator(
Criteria.where(fieldOne).regex(search, caseInsensitive),
Criteria.where(fieldTwo).regex(search, caseInsensitive),
..
But probably this could be made smoother if I used: https://docs.mongodb.com/manual/reference/operator/aggregation/addFields/
My problem is when I trying to use this in java like that:
Aggregation.addFields()
.addField("\$fullText")
.withValueOfExpression("\$concat", fieldOne, fieldTwo, ..
MongoTemplate sees only first param from above function
MongoTemplate : Executing aggregation: [{ "$addFields" : { "fullText" : "$concat"}},
Funny because if I write this like that:
.addField("\$fullText")
.withValueOfExpression(fieldOne, fieldTwo, "\$concat", ..
It returns me result filtered only by fieldOne and query looks like that: MongoTemplate : Executing aggregation: [{ "$addFields" : { "fullText" : "$fieldOne"}},
Did anyone have similar problem? Thanks in advance for any help :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
