Skip to content

Commit 06cb7d5

Browse files
committed
CXX-278 merge SERVER-14482 from upstream
SERVER-14482 Add ability to append RegEx into BSONArrayBuilder Conflicts: src/mongo/dbtests/jsobjtests.cpp
1 parent b733533 commit 06cb7d5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/mongo/bson/bsonobjbuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ namespace mongo {
821821
return *this;
822822
}
823823

824+
BSONArrayBuilder& appendRegex(const StringData& regex, const StringData& options = "") {
825+
_b.appendRegex(num(), regex, options);
826+
return *this;
827+
}
828+
824829
BSONArrayBuilder& appendTimestamp(unsigned long long ts) {
825830
_b.appendTimestamp(num(), ts);
826831
return *this;

src/mongo/dbtests/jsobjtests.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,17 +1716,25 @@ namespace JsobjTests {
17161716
objb.appendUndefined(objb.numStr(i++));
17171717
arrb.appendUndefined();
17181718

1719+
objb.appendRegex(objb.numStr(i++), "test", "imx");
1720+
arrb.appendRegex("test", "imx");
1721+
1722+
objb.append(objb.numStr(i++), BSONRegEx("test2", "s"));
1723+
arrb.append(BSONRegEx("test2", "s"));
1724+
17191725
BSONObj obj = objb.obj();
17201726
BSONArray arr = arrb.arr();
17211727

17221728
ASSERT_EQUALS(obj, arr);
17231729

1724-
BSONObj o = BSON( "obj" << obj << "arr" << arr << "arr2" << BSONArray(obj) );
1730+
BSONObj o = BSON( "obj" << obj << "arr" << arr << "arr2" << BSONArray(obj)
1731+
<< "regex" << BSONRegEx("reg", "x"));
17251732
//keyTest(o);
17261733

17271734
ASSERT_EQUALS(o["obj"].type(), Object);
17281735
ASSERT_EQUALS(o["arr"].type(), Array);
17291736
ASSERT_EQUALS(o["arr2"].type(), Array);
1737+
ASSERT_EQUALS(o["regex"].type(), RegEx);
17301738
}
17311739
}; DBTEST_SHIM_TEST(BSONArrayBuilderTest);
17321740

0 commit comments

Comments
 (0)