[CXX-907] how to get object size when constructing update_one Created: 06/May/16 Updated: 11/Sep/19 Resolved: 09/May/16 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | API |
| Affects Version/s: | 3.0.1 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Judy Han [X] | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Linux |
||
| Description |
|
I am starting to migrate from legacy driver 1.0.6 to new c++11 driver 3.0.1.
where variable "record" is of type "mongo::BSONObj" (in our use case, it's an insert 99% of the time) |
| Comments |
| Comment by Judy Han [X] [ 25/May/16 ] | ||||||||||||||||||||||
|
Hi David,
Thanks! | ||||||||||||||||||||||
| Comment by David Golden [ 24/May/16 ] | ||||||||||||||||||||||
|
It would help if you could describe your data model a bit better so that I can make a more helpful suggestion. Particularly:
Also, depending on what version of MongoDB you're using, particularly if you're using WiredTiger as a storage engine with compression, the size of the document in the database isn't the same as the uncompressed BSON document size anyway. Does that matter for your application? | ||||||||||||||||||||||
| Comment by Judy Han [X] [ 24/May/16 ] | ||||||||||||||||||||||
|
Hi David, | ||||||||||||||||||||||
| Comment by David Golden [ 09/May/16 ] | ||||||||||||||||||||||
|
replace_one will use slightly fewer bytes on the wire, since it doesn't have to wrap the document in a $set document. | ||||||||||||||||||||||
| Comment by Judy Han [X] [ 09/May/16 ] | ||||||||||||||||||||||
|
HI David, | ||||||||||||||||||||||
| Comment by David Golden [ 09/May/16 ] | ||||||||||||||||||||||
|
Hi, Judy. Do you need to use update_one? (Is there a possibility there is an existing document whose fields you want to preserve?) Otherwise, instead of using $set with update_one, you could use replace_one (still with upsert) in which case you would know the length of the replacement document. | ||||||||||||||||||||||
| Comment by Judy Han [X] [ 09/May/16 ] | ||||||||||||||||||||||
|
Hi David,
I can print out "eventUpdateBuilder.view().length()", but that is not really the size of the end object, isn't it? So in this case how do I get the size of the object? | ||||||||||||||||||||||
| Comment by David Golden [ 06/May/16 ] | ||||||||||||||||||||||
|
Hi, Judy. You can get the length from the length method on a document view:
Output:
|