Skip to content
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

Create array from field in update pipeline #4861

Open
Saljack opened this issue Dec 20, 2024 · 0 comments
Open

Create array from field in update pipeline #4861

Saljack opened this issue Dec 20, 2024 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@Saljack
Copy link

Saljack commented Dec 20, 2024

I would like to concat an array with another field. If I use normal update then I can use $push operator but in pipeline update I have to use $concatArrays. The problem is that I have to create array from a field reference but it is not possible because input string is replaced by just a field reference.
For example I have document:

{
  "myArray": ["something"],
   "myField": "else"
}

and as result I want to have:

{
  "myArray": ["something", "else"]
}

I want to run this MongoDB Update pipeline:

db.getCollection("myCollection").update({}, [
    { "$set": { myArray: {"$concatArrays": ["$myArray", [ "$myField" ] ]} }
])

I tried to rewrite it to:

.set("myArray").toValue(ArrayOperators.ConcatArrays.arrayOf("myArray").concat("[\"$myField\"]"))

but it is translated to:

{ "$set" : { "myArray" : { "$concatArrays" : ["$myArray", "$myField\"]"]}}}

I would use custom AggregationExpresion but it has to return Document but this is unfortunately array.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants