Skip to content

add uncapped_max_size feature to allow increasing max BSON size #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ uuid-1 = []
time-0_3 = []
# If enabled, implement Hash/Eq for Bson and Document
hashable = []
# If enabled, the maximum document size will be increased from the MongoDB cap
# of 16 MB to the BSON spec maximum size of 2^31 - 1
uncapped_max_size = []
serde_path_to_error = ["dep:serde_path_to_error"]
# if enabled, include serde_with interop.
# should be used in conjunction with chrono-0_4 or uuid-0_8.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t
| `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for `bson::DateTime` and `bson::Uuid`.| serde_with | no |
| `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | serde_path_to_error | no |
| `hashable` | Implement `core::hash::Hash` and `std::cmp::Eq` on `Bson` and `Document`. | n/a | no |
| `uncapped_max_size` | Increase the maximum document size from the MongoDB cap of 16 MB to the BSON spec maximum size of 2^31 - 1 bytes. | n/a | no |

## Overview of the BSON Format

Expand Down
3 changes: 3 additions & 0 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ pub(crate) use self::serde::{convert_unsigned_to_signed_raw, BsonVisitor};

pub(crate) use self::raw::Deserializer as RawDeserializer;

#[cfg(not(feature = "uncapped_max_size"))]
pub(crate) const MAX_BSON_SIZE: i32 = 16 * 1024 * 1024;
#[cfg(feature = "uncapped_max_size")]
pub(crate) const MAX_BSON_SIZE: i32 = i32::MAX;
pub(crate) const MIN_BSON_DOCUMENT_SIZE: i32 = 4 + 1; // 4 bytes for length, one byte for null terminator
pub(crate) const MIN_BSON_STRING_SIZE: i32 = 4 + 1; // 4 bytes for length, one byte for null terminator
pub(crate) const MIN_CODE_WITH_SCOPE_SIZE: i32 = 4 + MIN_BSON_STRING_SIZE + MIN_BSON_DOCUMENT_SIZE;
Expand Down