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

Feature: Merge Objects of an Array #3473

Open
2 tasks done
rahbari opened this issue Feb 10, 2024 · 0 comments
Open
2 tasks done

Feature: Merge Objects of an Array #3473

rahbari opened this issue Feb 10, 2024 · 0 comments
Labels
feature New feature or request triage This issue is new

Comments

@rahbari
Copy link

rahbari commented Feb 10, 2024

Is your feature request related to a problem?

We store incremental updates of a row in an array and use $mergeObjects operator in mongodb to merge them:
https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/

the only way I could find to do this in surreal is through scripting:
SELECT *, function() {return this.edits.reduce((a, b) => Object.assign(a, b))} AS edit FROM posts
But I believe the JS function performance is not as good as builtin functions for large dataset.

I think it's not even possible in custom functions because there is no object::assign.

Describe the solution

object::merge([]) function can do this.

Alternative methods

array::reduce() with object::assign() can also be used. both of these are helpful no matter object::merge exists or not.

SurrealDB version

1.1.1 for macos on aarch64

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@rahbari rahbari added feature New feature or request triage This issue is new labels Feb 10, 2024
@rahbari rahbari changed the title Feature: Merge Objects in Array Feature: Merge Objects of an Array Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request triage This issue is new
Projects
None yet
Development

No branches or pull requests

1 participant