-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement $set stage dsl #104
Conversation
/** | ||
* @see <a href="https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#add-element-to-an-array">Add Element to an Array</a> | ||
*/ | ||
fun addElementToAnArray(): AggregationResults<Score> { | ||
val aggregation = aggregation { | ||
match(Criteria.where(Score::id.toDotPath()).isEqualTo(1)) | ||
set { | ||
// TODO: add $concatArrays expression | ||
Score::homework set Document("\$concatArrays", listOf("\$${Score::homework.toDotPath()}", listOf(7))) | ||
} | ||
} | ||
|
||
return mongoTemplate.aggregate<Score>(aggregation, SCORES) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In example, we have to add 7
at the end of "homework" array.
db.scores.aggregate([
{ $match: { _id: 1 } },
{ $set: { homework: { $concatArrays: [ "$homework", [ 7 ] ] } } }
])
But, ConcatArrays not supported this. We can only concat value at the beginning maybe..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about using literal
expression. literals(listof(7))
but I can not sure if it works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻 it work well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think it is better to implement $concatArrays
without using ArrayOperator from spring.
It seems fine to leave it as it for now :)
8d91d06
to
80c6c4b
Compare
set { | ||
SalesDto::id set "2017" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 👍 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
resolve #72