[TASK] Standardize Mongo collection operation wrappers

Open
#596 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Stale
Tech stack
go, mongodb
Domain
backend, database

Research direction

Start in collection.go with the ReplaceOne, UpdateOne, FindOne, and FindOneAndUpdate wrappers, then inspect their callers and existing tests to understand the current return-value expectations. Update the affected interfaces consistently and verify that callers handle the new results and that the acceptance criteria are covered by the test suite.

Written by the indexing model from the issue text.

Description

enhancement
Description

The ReplaceOne and UpdateOne wrapper functions in collection.go do not behave the same way, which can lead to some confusion. ReplaceOne does not return mongo.UpdateResult and will return an error if no document is found to replace, but UpdateOne does return mongo.UpdateResult and will not return an error.

Also, FindOne and FindOneAndUpdate return an error that does not clearly indicate whether the requested document was found.

Acceptance Criteria
  • Return mongo.UpdateResult object and error from ReplaceOne to standardize with UpdateOne
  • Return (bool, error) from FindOne and FindOneAndUpdate to give a better indication of whether the requested document was found

@petyos, @shurwit please let me know what you think of these proposed changes. Thanks.

Dominant language
Go
Stars
3
Forks
2
Avg merge
5h 45m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rokwire/core-building-block

All issues in rokwire/core-building-block

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.