[CXX-1430] insert_many does not return whether transaction was acknowledged Created: 02/Sep/17 Updated: 27/Oct/23 Resolved: 22/Jan/18 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | w | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
The official specification for insert_many is that it returns both a list of inserted ID's, but also whether the transaction was acknowledged (https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/). This is followed by PyMongo as well, but it seems that the C++ driver does not return this (http://mongodb.github.io/mongo-cxx-driver/api/mongocxx-v3/classmongocxx_1_1result_1_1insert__many.html). Is there a reason for this? |
| Comments |
| Comment by Andrew Morrow (Inactive) [ 22/Jan/18 ] |
|
Hi sebastianb99 - This isn't actually a non-conformance with the specification. As you may notice in the results section of the driver CRUD spec, the acknowledged flag is not a required field in the results type. Note what it says though: if the acknowledged field is part of the result structure, and the field has the value true, then the other fields of the structure have undefined values. But in C++, we have a better way to express that concept. Instead of having the acknowledged field and invalid internal state, we can simply use std::optional<result_type> to indicate whether the result type is present or not. All of the CRUD methods on mongocxx::collection that return result:: types actually return stdx::optional<result::type>. In the case of mongocxx::collection::insert_many the return type is stdx::optional<result::insert_many>. If the returned object is a disengaged optional, it means that no results will be returned/awaited because the operation was not performed in a manner that required it. Happy to answer any further questions on this, but I'm going to close this ticket as works as designed. |
| Comment by Matt Broadstone [ 02/Sep/17 ] |
|
sebastianb99 You're correct that this is out of line with our CRUD spec, thanks for pointing this out! My guess is that its not provided by the underlaying C driver, but I'll look into this next week. |