[GODRIVER-861] Improvement Upsert in FindAndModify Created: 05/Mar/19 Updated: 19/Aug/21 Resolved: 18/Apr/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | CRUD |
| Affects Version/s: | 1.0.0-rc2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Quang Tong | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
WHY: - I'm integrating mongo-go-driver into our project to replace the mgo library. At the command findAndModify, I want to get the UpdatedExisting field in FindAndModify struct when using the Upsert option. That will let me know the document is inserted or updated. For example: FindOneAndUpdate function.
|
| Comments |
| Comment by Vladimir Antonov [ 19/Aug/21 ] |
|
Hi guys! Jeffry's answer seem a bit inaccurate because the Ruby driver had this option back in 2013. P.S. Running generic RunCommand helper method is not an option since there's a lot of internal boilerplate stuff prior to the findAndModify call which just can't be omitted and can't be called from the external package.
|
| Comment by Jeffrey Yemin [ 02/Apr/19 ] |
|
Hi tkquang, Currently none of the MongoDB drivers, nor the shell, provide access via the various findAndModify helper method (FindOneAndUpdate, etc.) to the lastErrorObject from the command response, which is what contains the updatedExisting field. They just return the document itself. If your application requires access to that field, the best way to do that is to execute the findAndModify command via the generic RunCommand helper method. |