@@ -1000,6 +1000,39 @@ TEST_CASE("CRUD functionality", "[driver::collection]") {
10001000 return results;
10011001 };
10021002
1003+ SECTION (" group" ) {
1004+ coll.insert_one (document{} << " x" << 1 << finalize);
1005+ coll.insert_one (document{} << " x" << 1 << finalize);
1006+ coll.insert_one (document{} << " x" << 2 << finalize);
1007+
1008+ pipeline.group (document{} << " _id"
1009+ << " $x" << finalize);
1010+ // Add a sort to the pipeline, so below tests can make assumptions about result order.
1011+ pipeline.sort (document{} << " _id" << 1 << finalize);
1012+ auto cursor = coll.aggregate (pipeline);
1013+
1014+ auto results = get_results (std::move (cursor));
1015+ REQUIRE (results.size () == 2 );
1016+ REQUIRE (results[0 ].view ()[" _id" ].get_int32 () == 1 );
1017+ REQUIRE (results[1 ].view ()[" _id" ].get_int32 () == 2 );
1018+ }
1019+
1020+ SECTION (" limit" ) {
1021+ coll.insert_one (document{} << " x" << 1 << finalize);
1022+ coll.insert_one (document{} << " x" << 2 << finalize);
1023+ coll.insert_one (document{} << " x" << 3 << finalize);
1024+
1025+ // Add a sort to the pipeline, so below tests can make assumptions about result order.
1026+ pipeline.sort (document{} << " x" << 1 << finalize);
1027+ pipeline.limit (2 );
1028+ auto cursor = coll.aggregate (pipeline);
1029+
1030+ auto results = get_results (std::move (cursor));
1031+ REQUIRE (results.size () == 2 );
1032+ REQUIRE (results[0 ].view ()[" x" ].get_int32 () == 1 );
1033+ REQUIRE (results[1 ].view ()[" x" ].get_int32 () == 2 );
1034+ }
1035+
10031036 SECTION (" lookup" ) {
10041037 coll.insert_one (document{} << " x" << 0 << finalize);
10051038 coll.insert_one (document{} << " x" << 1 << " y" << 0 << finalize);
@@ -1037,6 +1070,125 @@ TEST_CASE("CRUD functionality", "[driver::collection]") {
10371070 auto results = get_results (std::move (cursor));
10381071 REQUIRE (results.size () == 2 );
10391072 }
1073+
1074+ SECTION (" out" ) {
1075+ coll.insert_one (document{} << " x" << 1 << " y" << 1 << finalize);
1076+
1077+ pipeline.project (document{} << " x" << 1 << finalize);
1078+ pipeline.out (coll.name ().to_string ());
1079+ auto cursor = coll.aggregate (pipeline);
1080+
1081+ if (test_util::get_max_wire_version (mongodb_client) >= 1 ) {
1082+ // The server supports out().
1083+ auto results = get_results (std::move (cursor));
1084+ REQUIRE (results.empty ());
1085+
1086+ auto collection_contents = get_results (coll.find ({}));
1087+ REQUIRE (collection_contents.size () == 1 );
1088+ REQUIRE (collection_contents[0 ].view ()[" x" ].get_int32 () == 1 );
1089+ REQUIRE (!collection_contents[0 ].view ()[" y" ]);
1090+ } else {
1091+ // The server does not support out().
1092+ REQUIRE_THROWS_AS (get_results (std::move (cursor)), operation_exception);
1093+ }
1094+ }
1095+
1096+ SECTION (" project" ) {
1097+ coll.insert_one (document{} << " x" << 1 << " y" << 1 << finalize);
1098+
1099+ pipeline.project (document{} << " x" << 1 << finalize);
1100+ auto cursor = coll.aggregate (pipeline);
1101+
1102+ auto results = get_results (std::move (cursor));
1103+ REQUIRE (results.size () == 1 );
1104+ REQUIRE (results[0 ].view ()[" x" ].get_int32 () == 1 );
1105+ REQUIRE (!results[0 ].view ()[" y" ]);
1106+ }
1107+
1108+ SECTION (" redact" ) {
1109+ coll.insert_one (document{} << " x" << open_document << " secret" << 1 << close_document
1110+ << " y" << 1 << finalize);
1111+
1112+ pipeline.redact (document{} << " $cond" << open_document << " if" << open_document << " $eq"
1113+ << open_array << " $secret" << 1 << close_array
1114+ << close_document << " then"
1115+ << " $$PRUNE"
1116+ << " else"
1117+ << " $$DESCEND" << close_document << finalize);
1118+ auto cursor = coll.aggregate (pipeline);
1119+
1120+ if (test_util::get_max_wire_version (mongodb_client) >= 1 ) {
1121+ // The server supports redact().
1122+ auto results = get_results (std::move (cursor));
1123+ REQUIRE (results.size () == 1 );
1124+ REQUIRE (!results[0 ].view ()[" x" ]);
1125+ REQUIRE (results[0 ].view ()[" y" ].get_int32 () == 1 );
1126+ } else {
1127+ // The server does not support redact().
1128+ REQUIRE_THROWS_AS (get_results (std::move (cursor)), operation_exception);
1129+ }
1130+ }
1131+
1132+ SECTION (" sample" ) {
1133+ coll.insert_one ({});
1134+ coll.insert_one ({});
1135+ coll.insert_one ({});
1136+ coll.insert_one ({});
1137+
1138+ pipeline.sample (3 );
1139+ auto cursor = coll.aggregate (pipeline);
1140+
1141+ if (test_util::get_max_wire_version (mongodb_client) >= 4 ) {
1142+ // The server supports sample().
1143+ auto results = get_results (std::move (cursor));
1144+ REQUIRE (results.size () == 3 );
1145+ } else {
1146+ // The server does not support sample().
1147+ REQUIRE_THROWS_AS (get_results (std::move (cursor)), operation_exception);
1148+ }
1149+ }
1150+
1151+ SECTION (" skip" ) {
1152+ coll.insert_one (document{} << " x" << 1 << finalize);
1153+ coll.insert_one (document{} << " x" << 2 << finalize);
1154+ coll.insert_one (document{} << " x" << 3 << finalize);
1155+
1156+ // Add a sort to the pipeline, so below tests can make assumptions about result order.
1157+ pipeline.sort (document{} << " x" << 1 << finalize);
1158+ pipeline.skip (1 );
1159+ auto cursor = coll.aggregate (pipeline);
1160+
1161+ auto results = get_results (std::move (cursor));
1162+ REQUIRE (results.size () == 2 );
1163+ REQUIRE (results[0 ].view ()[" x" ].get_int32 () == 2 );
1164+ REQUIRE (results[1 ].view ()[" x" ].get_int32 () == 3 );
1165+ }
1166+
1167+ SECTION (" sort" ) {
1168+ coll.insert_one (document{} << " x" << 1 << finalize);
1169+ coll.insert_one (document{} << " x" << 2 << finalize);
1170+ coll.insert_one (document{} << " x" << 3 << finalize);
1171+
1172+ pipeline.sort (document{} << " x" << -1 << finalize);
1173+ auto cursor = coll.aggregate (pipeline);
1174+
1175+ auto results = get_results (std::move (cursor));
1176+ REQUIRE (results.size () == 3 );
1177+ REQUIRE (results[0 ].view ()[" x" ].get_int32 () == 3 );
1178+ REQUIRE (results[1 ].view ()[" x" ].get_int32 () == 2 );
1179+ REQUIRE (results[2 ].view ()[" x" ].get_int32 () == 1 );
1180+ }
1181+
1182+ SECTION (" unwind" ) {
1183+ coll.insert_one (document{} << " x" << open_array << 1 << 2 << 3 << 4 << 5 << close_array
1184+ << finalize);
1185+
1186+ pipeline.unwind (" $x" );
1187+ auto cursor = coll.aggregate (pipeline);
1188+
1189+ auto results = get_results (std::move (cursor));
1190+ REQUIRE (results.size () == 5 );
1191+ }
10401192 }
10411193
10421194 SECTION (" aggregation with collation" , " [collection]" ) {
0 commit comments