Skip to content

Commit 09ce866

Browse files
committed
Parse sort option for replaceOne and updateOne
1 parent 4280b22 commit 09ce866

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: src/MongoDB/BulkWriteCommand.c

+24
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,18 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommand, replaceOne)
507507
bson_value_destroy(&bhint);
508508
}
509509

510+
if (php_array_existsc(zoptions, "sort")) {
511+
bson_t bsort = BSON_INITIALIZER;
512+
513+
if (!phongo_bwc_parse_document(php_array_fetchc_deref(zoptions, "sort"), &bsort, "sort")) {
514+
bson_destroy(&bsort);
515+
goto cleanup;
516+
}
517+
518+
mongoc_bulkwrite_replaceoneopts_set_sort(opts, &bsort);
519+
bson_destroy(&bsort);
520+
}
521+
510522
if (php_array_existsc(zoptions, "upsert")) {
511523
mongoc_bulkwrite_replaceoneopts_set_upsert(opts, php_array_fetchc_bool(zoptions, "upsert"));
512524
}
@@ -703,6 +715,18 @@ static PHP_METHOD(MongoDB_Driver_BulkWriteCommand, updateOne)
703715
bson_value_destroy(&bhint);
704716
}
705717

718+
if (php_array_existsc(zoptions, "sort")) {
719+
bson_t bsort = BSON_INITIALIZER;
720+
721+
if (!phongo_bwc_parse_document(php_array_fetchc_deref(zoptions, "sort"), &bsort, "sort")) {
722+
bson_destroy(&bsort);
723+
goto cleanup;
724+
}
725+
726+
mongoc_bulkwrite_updateoneopts_set_sort(opts, &bsort);
727+
bson_destroy(&bsort);
728+
}
729+
706730
if (php_array_existsc(zoptions, "upsert")) {
707731
mongoc_bulkwrite_updateoneopts_set_upsert(opts, php_array_fetchc_bool(zoptions, "upsert"));
708732
}

0 commit comments

Comments
 (0)