Skip to content

Commit fdbf863

Browse files
Trevader24135Trevor Klingler
and
Trevor Klingler
authored
add uncapped_max_size feature to allow increasing max BSON size (#528)
* add `uncapped_max_size` feature to allow increasing max BSON size * fix typo in `uncapped_max_size` feature table in readme --------- Co-authored-by: Trevor Klingler <[email protected]>
1 parent 2a638a1 commit fdbf863

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ uuid-1 = []
4545
time-0_3 = []
4646
# If enabled, implement Hash/Eq for Bson and Document
4747
hashable = []
48+
# If enabled, the maximum document size will be increased from the MongoDB cap
49+
# of 16 MB to the BSON spec maximum size of 2^31 - 1
50+
uncapped_max_size = []
4851
serde_path_to_error = ["dep:serde_path_to_error"]
4952
# if enabled, include serde_with interop.
5053
# should be used in conjunction with chrono-0_4 or uuid-0_8.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t
5555
| `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 |
5656
| `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 |
5757
| `hashable` | Implement `core::hash::Hash` and `std::cmp::Eq` on `Bson` and `Document`. | n/a | no |
58+
| `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 |
5859

5960
## Overview of the BSON Format
6061

src/de/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ pub(crate) use self::serde::{convert_unsigned_to_signed_raw, BsonVisitor};
4747

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

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

0 commit comments

Comments
 (0)