[GODRIVER-2999] Implemente ReplaceByID Created: 30/Sep/23  Updated: 11/Oct/23  Resolved: 05/Oct/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Tomás Warynyca Assignee: Preston Vasquez
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-3012 Create a CRUD query filters helper Backlog
is related to GODRIVER-1807 Add UpdateByID method to Collection Closed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Replicate how UpdateByID works



 Comments   
Comment by Matt Dale [ 11/Oct/23 ]

Adding more context to the decision to not add ReplaceByID:
We recognize that having to redefine the same filter over and over can be tedious and adds an opportunity to introduce typos. However, adding [operation]ByID methods for all of the frequently used operation methods is not a sustainable pattern. Instead, we are experimenting with a query filter helper to make writing filters easier and safer and that can work with any operation function. See GODRIVER-3012 for more detail.

Comment by Preston Vasquez [ 05/Oct/23 ]

tomas.warynyca@outlook.com We are likely going to deprecate UpdateByID in V2. The reason for such convenience functions are unclear, as it is straight-forward for a user to wrap existing collection methods for reuse. The same would apply to requests for additional convenience functions like FindByID or ReplaceByID:

func replaceByID(id interface{}) {
    filter := bson.D{{Key: "_id", Value: b.ID}}
    _, _ := db.MongoInstance.Function().ReplaceOne(ctx, filter, b)
}

Comment by Tomás Warynyca [ 05/Oct/23 ]

Good afternoon, instead of having to be adding the filter all the time when I have to replace by ID in different saving methods that I have
It would work like UpdateByID does, it receives the ID as a parameter and internally adds the filter.

Current
filter := bson.D{{Key: "_id", Value: b.ID}}
_, _ := db.MongoInstance.Function().ReplaceOne(ctx, filter, b)

New
_, _ := db.MongoInstance.Function().ReplaceByID(ctx, b.ID, b)

Comment by Preston Vasquez [ 05/Oct/23 ]

tomas.warynyca@outlook.com Thanks for the ticket! Would you mind sharing your use-case for this?

Comment by PM Bot [ 30/Sep/23 ]

Hi tomas.warynyca@outlook.com, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Thu Feb 08 08:39:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.