From ab95c57e9a77d6bfe0bc602d47c6d9636e265c48 Mon Sep 17 00:00:00 2001 From: Serhii Lysenko Date: Thu, 31 Oct 2024 12:42:35 +0000 Subject: [PATCH] MissingFieldsDontAffectKeyOrder test --- .../document_value/document_value_test.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/mongo/db/exec/document_value/document_value_test.cpp b/src/mongo/db/exec/document_value/document_value_test.cpp index 0267e5d4567..01ac8b81c4e 100644 --- a/src/mongo/db/exec/document_value/document_value_test.cpp +++ b/src/mongo/db/exec/document_value/document_value_test.cpp @@ -101,6 +101,29 @@ void assertRoundTrips(const Document& document1) { ASSERT_DOCUMENT_EQ(document1, document2); } +TEST(BF35347, MissingFieldsDontAffectKeyOrder) { + + Value missing; + Document doc = fromBson(BSON("_id" << 1)); + + MutableDocument out(doc); + MutableDocument out2(doc); + + out2.setField("a"_sd, missing); + + out.setField("b"_sd, Value(5)); + out2.setField("b"_sd, Value(5)); + + out.setField("a", Value("str"_sd)); + out2.setField("a", Value("str"_sd)); + + auto toString = [](auto&& val) { + return val.freeze().toBson().toString(); + }; + + ASSERT_EQUALS(toString(out), toString(out2)); +} + TEST(DocumentConstruction, Default) { Document document; ASSERT_EQUALS(0ULL, document.computeSize()); -- 2.34.1