Update an object in array
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 118
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
Let's say I have table posts and every post have an array called comments with objects inside to describe the comment like so comments: [{author: 'Joe', adminComment: true, text: 'Update me'}]
How would you update the text of the comment? I saw that there is an issue for that but the solution is not available yet.
Stack Overflow to the rescue! There is a good explanation for the update query. The problem was that it is with hard-coded index for the element of the array. So here is a full example for updating a single comment that worked for me:
let post_id = 123;
let comment_id = 23434;
let findCommentIndex =
r.table("posts")
.get(post_id)("comments")
.offsetsOf(
r.row("id").match(comment_id)
)
.nth(0)
let update =
findCommentIndex.do((index) => {
return r.table('posts')
.get(post_id)
.update((post) => {
return {
channels: post('comments').changeAt(index,
post('comments')
.nth(index)
.merge({'text': 'updated!'})
)
}
})
})
This operations should be a lot more easier and I hope someday they will be but right now it would be cool if we have some examples like this one on the docs or cookbook because I'm sure I'm not the only one that lost a lot of time to figure this one out.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue points to the docs or cookbook as the entry point and includes a full embedded-comment update example; start by locating the relevant update and array documentation and reviewing the linked RethinkDB issue. Done means adding a clear example for updating a comment without a hard-coded array index, with wording consistent with the surrounding docs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- databases, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100