@@ -9,7 +9,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
9
9
/* Basic Sanity Checks */
10
10
coll . drop ( ) ;
11
11
12
- assert . writeOK ( coll . insert ( [
12
+ assert . commandWorked ( coll . insert ( [
13
13
{ _id : 0 , year : 2017 , month : 6 , day : 19 , hour : 15 , minute : 13 , second : 25 , millisecond : 713 } ,
14
14
{
15
15
_id : 1 ,
@@ -105,7 +105,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
105
105
106
106
coll . drop ( ) ;
107
107
108
- assert . writeOK ( coll . insert ( [
108
+ assert . commandWorked ( coll . insert ( [
109
109
{
110
110
_id : 0 ,
111
111
year : 2017 ,
@@ -389,7 +389,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
389
389
390
390
coll . drop ( ) ;
391
391
392
- assert . writeOK ( coll . insert ( [
392
+ assert . commandWorked ( coll . insert ( [
393
393
{ _id : 0 } ,
394
394
] ) ) ;
395
395
@@ -421,7 +421,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
421
421
422
422
coll . drop ( ) ;
423
423
424
- assert . writeOK ( coll . insert ( [
424
+ assert . commandWorked ( coll . insert ( [
425
425
{ _id : 0 , falseValue : false } ,
426
426
] ) ) ;
427
427
@@ -453,7 +453,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
453
453
454
454
coll . drop ( ) ;
455
455
456
- assert . writeOK ( coll . insert ( [
456
+ assert . commandWorked ( coll . insert ( [
457
457
{ _id : 0 , outOfRangeValue : 10002 } ,
458
458
] ) ) ;
459
459
@@ -472,7 +472,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
472
472
473
473
coll . drop ( ) ;
474
474
475
- assert . writeOK ( coll . insert ( [ {
475
+ assert . commandWorked ( coll . insert ( [ {
476
476
_id : 0 ,
477
477
minusOne : - 1 ,
478
478
zero : 0 ,
@@ -548,7 +548,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
548
548
*/
549
549
coll . drop ( ) ;
550
550
551
- assert . writeOK ( coll . insert ( [ {
551
+ assert . commandWorked ( coll . insert ( [ {
552
552
_id : 0 ,
553
553
veryBigDoubleA : 18014398509481984.0 ,
554
554
veryBigDecimal128A : NumberDecimal ( "9223372036854775807" ) , // 2^63-1
@@ -580,12 +580,113 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
580
580
[ { $project : { date : { "$dateFromParts" : { year : 1970 , millisecond : "$veryBigDecimal128B" } } } } ] ;
581
581
assertErrMsgContains ( coll , pipeline , 40515 , "'millisecond' must evaluate to an integer" ) ;
582
582
583
+ /* --------------------------------------------------------------------------------------- */
584
+ /* Testing that year values are only allowed in the range [0, 9999] and that month, day, hour,
585
+ * and minute values are only allowed in the range [-32,768, 32,767]. */
586
+ coll . drop ( ) ;
587
+
588
+ assert . commandWorked ( coll . insert ( [ {
589
+ _id : 0 ,
590
+ bigYear : 10000 ,
591
+ smallYear : - 1 ,
592
+ prettyBigInt : 32768 ,
593
+ prettyBigNegativeInt : - 32769
594
+ } ] ) ) ;
595
+
596
+ pipeline = [ { $project : { date : { "$dateFromParts" : { year : "$bigYear" } } } } ] ;
597
+ assertErrMsgContains (
598
+ coll , pipeline , 40523 , "'year' must evaluate to an integer in the range 0 to 9999" ) ;
599
+
600
+ pipeline = [ { $project : { date : { "$dateFromParts" : { year : "$smallYear" } } } } ] ;
601
+ assertErrMsgContains (
602
+ coll , pipeline , 40523 , "'year' must evaluate to an integer in the range 0 to 9999" ) ;
603
+
604
+ pipeline = [ { $project : { date : { "$dateFromParts" : { year : 1970 , month : "$prettyBigInt" } } } } ] ;
605
+ assertErrMsgContains (
606
+ coll , pipeline , 31034 , "'month' must evaluate to a value in the range [-32768, 32767]" ) ;
607
+
608
+ pipeline =
609
+ [ { $project : { date : { "$dateFromParts" : { year : 1970 , month : "$prettyBigNegativeInt" } } } } ] ;
610
+ assertErrMsgContains (
611
+ coll , pipeline , 31034 , "'month' must evaluate to a value in the range [-32768, 32767]" ) ;
612
+
613
+ pipeline =
614
+ [ { $project : { date : { "$dateFromParts" : { year : 1970 , month : 1 , day : "$prettyBigInt" } } } } ] ;
615
+ assertErrMsgContains (
616
+ coll , pipeline , 31034 , "'day' must evaluate to a value in the range [-32768, 32767]" ) ;
617
+
618
+ pipeline = [ {
619
+ $project :
620
+ { date : { "$dateFromParts" : { year : 1970 , month : 1 , day : "$prettyBigNegativeInt" } } }
621
+ } ] ;
622
+ assertErrMsgContains (
623
+ coll , pipeline , 31034 , "'day' must evaluate to a value in the range [-32768, 32767]" ) ;
624
+
625
+ pipeline = [ { $project : { date : { "$dateFromParts" : { year : 1970 , hour : "$prettyBigInt" } } } } ] ;
626
+ assertErrMsgContains (
627
+ coll , pipeline , 31034 , "'hour' must evaluate to a value in the range [-32768, 32767]" ) ;
628
+
629
+ pipeline =
630
+ [ { $project : { date : { "$dateFromParts" : { year : 1970 , hour : "$prettyBigNegativeInt" } } } } ] ;
631
+ assertErrMsgContains (
632
+ coll , pipeline , 31034 , "'hour' must evaluate to a value in the range [-32768, 32767]" ) ;
633
+
634
+ pipeline =
635
+ [ { $project : { date : { "$dateFromParts" : { year : 1970 , hour : 0 , minute : "$prettyBigInt" } } } } ] ;
636
+ assertErrMsgContains (
637
+ coll , pipeline , 31034 , "'minute' must evaluate to a value in the range [-32768, 32767]" ) ;
638
+
639
+ pipeline = [ {
640
+ $project :
641
+ { date : { "$dateFromParts" : { year : 1970 , hour : 0 , minute : "$prettyBigNegativeInt" } } }
642
+ } ] ;
643
+ assertErrMsgContains (
644
+ coll , pipeline , 31034 , "'minute' must evaluate to a value in the range [-32768, 32767]" ) ;
645
+
646
+ pipeline = [ { $project : { date : { "$dateFromParts" : { isoWeekYear : "$bigYear" } } } } ] ;
647
+ assertErrMsgContains (
648
+ coll , pipeline , 31095 , "'isoWeekYear' must evaluate to an integer in the range 0 to 9999" ) ;
649
+
650
+ pipeline = [ { $project : { date : { "$dateFromParts" : { isoWeekYear : "$smallYear" } } } } ] ;
651
+ assertErrMsgContains (
652
+ coll , pipeline , 31095 , "'isoWeekYear' must evaluate to an integer in the range 0 to 9999" ) ;
653
+
654
+ pipeline =
655
+ [ { $project : { date : { "$dateFromParts" : { isoWeekYear : 1970 , isoWeek : "$prettyBigInt" } } } } ] ;
656
+ assertErrMsgContains (
657
+ coll , pipeline , 31034 , "'isoWeek' must evaluate to a value in the range [-32768, 32767]" ) ;
658
+
659
+ pipeline = [ {
660
+ $project :
661
+ { date : { "$dateFromParts" : { isoWeekYear : 1970 , isoWeek : "$prettyBigNegativeInt" } } }
662
+ } ] ;
663
+ assertErrMsgContains (
664
+ coll , pipeline , 31034 , "'isoWeek' must evaluate to a value in the range [-32768, 32767]" ) ;
665
+
666
+ pipeline = [
667
+ { $project : { date : { "$dateFromParts" : { isoWeekYear : 1970 , isoDayOfWeek : "$prettyBigInt" } } } }
668
+ ] ;
669
+ assertErrMsgContains ( coll ,
670
+ pipeline ,
671
+ 31034 ,
672
+ "'isoDayOfWeek' must evaluate to a value in the range [-32768, 32767]" ) ;
673
+
674
+ pipeline = [ {
675
+ $project : {
676
+ date : { "$dateFromParts" : { isoWeekYear : 1970 , isoDayOfWeek : "$prettyBigNegativeInt" } }
677
+ }
678
+ } ] ;
679
+ assertErrMsgContains ( coll ,
680
+ pipeline ,
681
+ 31034 ,
682
+ "'isoDayOfWeek' must evaluate to a value in the range [-32768, 32767]" ) ;
683
+
583
684
/* --------------------------------------------------------------------------------------- */
584
685
/* Testing wrong arguments */
585
686
586
687
coll . drop ( ) ;
587
688
588
- assert . writeOK ( coll . insert ( [
689
+ assert . commandWorked ( coll . insert ( [
589
690
{ _id : 0 } ,
590
691
] ) ) ;
591
692
@@ -630,7 +731,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
630
731
631
732
coll . drop ( ) ;
632
733
633
- assert . writeOK ( coll . insert ( [
734
+ assert . commandWorked ( coll . insert ( [
634
735
{ _id : 0 , floatField : 2017.5 , decimalField : NumberDecimal ( "2017.5" ) } ,
635
736
] ) ) ;
636
737
@@ -653,7 +754,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
653
754
654
755
coll . drop ( ) ;
655
756
656
- assert . writeOK ( coll . insert ( [
757
+ assert . commandWorked ( coll . insert ( [
657
758
{ _id : 0 , year : NumberDecimal ( "2017" ) , month : 6.0 , day : NumberInt ( 19 ) , hour : NumberLong ( 15 ) } ,
658
759
{
659
760
_id : 1 ,
@@ -733,7 +834,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
733
834
734
835
coll . drop ( ) ;
735
836
736
- assert . writeOK ( coll . insert ( [
837
+ assert . commandWorked ( coll . insert ( [
737
838
{
738
839
_id : 0 ,
739
840
year : NumberDecimal ( "2017" ) ,
@@ -783,7 +884,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and assertE
783
884
784
885
coll . drop ( ) ;
785
886
786
- assert . writeOK ( coll . insert ( [
887
+ assert . commandWorked ( coll . insert ( [
787
888
{
788
889
_id : 0 ,
789
890
isoWeekYear : NumberDecimal ( "2017" ) ,
0 commit comments