[CXX-909] Force generate oid in mongo cxx client Created: 13/May/16 Updated: 17/May/16 Resolved: 16/May/16 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | API, BSON |
| Affects Version/s: | legacy-1.1.0, legacy-1.1.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | ethan zhang | Assignee: | Andrew Morrow (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
hi, I am a develop from LeTV China. I use mongo cxx client ver. legacy, and have a question with the oid of the insert operation. In the github wiki, I have read below:
It means that mongo client will not generate the oid for me unless I included it explicitly in the BSONbuilder.
So, will the mongo client give the choice to user to select who will genrate the oid, from the mongo client or the mongo server. |
| Comments |
| Comment by ethan zhang [ 17/May/16 ] |
|
ok, Thank you guys. |
| Comment by Andrew Morrow (Inactive) [ 16/May/16 ] |
|
unpeeled_onion@outlook.com I'm closing this issue as the driver is working as designed. Whether or not the server or the driver does the work of inserting the _id, the observable effect is "as if" the server had done the _id generation. Clients should not care which way it is done, and in fact it is beneficial if it is done in the driver, as pointed out above, since otherwise there is no way for the driver to report to the user the _id of the object that it was inserted. |
| Comment by David Golden [ 16/May/16 ] |
|
unpeeled_onion@outlook.com, drivers generate OIDs client-side so they can provide users with the _id of the document just inserted (as the server doesn't return _id on insert the way it does for upsert). |
| Comment by Andrew Morrow (Inactive) [ 16/May/16 ] |
|
unpeeled_onion@outlook.com - Yes, but why does it matter? Why do you care if the server sets the _id field, or if the client does it? From the perspective of a user of the driver, the externally observable effects are the same. Almost all MongoDB drivers do client side _id generation. If, somehow, you are using a driver that doesn't, the server will then take care of it as a last resort. |
| Comment by ethan zhang [ 16/May/16 ] |
|
Hi, Andrew |
| Comment by Andrew Morrow (Inactive) [ 14/May/16 ] |
|
First, are you saying that the GENOID macro isn't working correctly for you? I don't entirely understand the part about "Unknown macro". As far as whether the _id field is inserted automatically by the server or the client, why does it matter? The observed effects are the same. As a user of the driver, if you insert an object without an _id, one will be added for you. Why should the application care whether that was done on the client or on the server? |