[GODRIVER-2865] Export a constant for the max size of a BSON document Created: 05/Jun/23  Updated: 13/Jun/23  Resolved: 13/Jun/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Unknown
Reporter: Felipe Gasper Assignee: Matt Dale
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

It would be nice to be able to write `bson.MaxDocSize` instead of hard-coding 16 MiB. I see that the driver internally defines such a constant; this request proposes to export that.

Thank you!



 Comments   
Comment by Matt Dale [ 13/Jun/23 ]

felipe.gasper@mongodb.com yeah, it's not exactly constant, although it seems to only change about once per decade. You can pull the real value from a ServerDescriptionChangedEvent.

E.g. code for printing MaxDocumentSize:

monitor := &event.ServerMonitor{
	ServerDescriptionChanged: func(e *event.ServerDescriptionChangedEvent) {
		fmt.Printf(
			"MaxDocumentSize for %q: %d\n",
			e.Address,
			e.NewDescription.MaxDocumentSize)
	},
}
 
client, err := mongo.Connect(
	context.Background(),
	options.Client().
		ApplyURI("mongodb://localhost:27017").
		SetServerMonitor(monitor))
if err != nil {
	panic(err)
}
 
// Run operations...

Comment by Felipe Gasper [ 13/Jun/23 ]

Apparently the max BSON size isn’t as “constant” as I thought.

Comment by Felipe Gasper [ 13/Jun/23 ]

matt.dale@mongodb.com: We use such a constant, e.g., in the migration-verifier to ensure that we can write out appropriate documents to note recheck tasks.

If the max BSON size varies according to the server version (and theoretically could change again), then I guess this isn’t necessarily the best idea.

Comment by PM Bot [ 13/Jun/23 ]

Hi felipe.gasper@mongodb.com! GODRIVER-2865 is awaiting your response.

If this is still an issue for you, please open Jira to review the latest status and provide your feedback. Thanks!

Comment by Matt Dale [ 05/Jun/23 ]

Hey felipe.gasper@mongodb.com thanks for the suggestion! I'm concerned about adding a constant for the maximum BSON document size because it technically depends on the DB version (although it hasn't changed in a long time; see a reference to previous changes here).

Can you give me more details about how you would use a maximum document size constant? What logic depends on knowing the maximum document size? Do you have a way to handle errors from the database if you send a document that is too large?

Generated at Thu Feb 08 08:39:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.