@@ -140,6 +140,10 @@ func (dvd DefaultValueDecoders) BooleanDecodeValue(dctx DecodeContext, vr bsonrw
140
140
if err = vr .ReadNull (); err != nil {
141
141
return err
142
142
}
143
+ case bsontype .Undefined :
144
+ if err = vr .ReadUndefined (); err != nil {
145
+ return err
146
+ }
143
147
default :
144
148
return fmt .Errorf ("cannot decode %v into a boolean" , vrType )
145
149
}
@@ -195,6 +199,10 @@ func (dvd DefaultValueDecoders) IntDecodeValue(dc DecodeContext, vr bsonrw.Value
195
199
if err = vr .ReadNull (); err != nil {
196
200
return err
197
201
}
202
+ case bsontype .Undefined :
203
+ if err = vr .ReadUndefined (); err != nil {
204
+ return err
205
+ }
198
206
default :
199
207
return fmt .Errorf ("cannot decode %v into an integer type" , vrType )
200
208
}
@@ -354,6 +362,10 @@ func (dvd DefaultValueDecoders) FloatDecodeValue(ec DecodeContext, vr bsonrw.Val
354
362
if err = vr .ReadNull (); err != nil {
355
363
return err
356
364
}
365
+ case bsontype .Undefined :
366
+ if err = vr .ReadUndefined (); err != nil {
367
+ return err
368
+ }
357
369
default :
358
370
return fmt .Errorf ("cannot decode %v into a float32 or float64 type" , vrType )
359
371
}
@@ -409,6 +421,8 @@ func (DefaultValueDecoders) JavaScriptDecodeValue(dctx DecodeContext, vr bsonrw.
409
421
js , err = vr .ReadJavascript ()
410
422
case bsontype .Null :
411
423
err = vr .ReadNull ()
424
+ case bsontype .Undefined :
425
+ err = vr .ReadUndefined ()
412
426
default :
413
427
return fmt .Errorf ("cannot decode %v into a primitive.JavaScript" , vrType )
414
428
}
@@ -452,6 +466,10 @@ func (DefaultValueDecoders) SymbolDecodeValue(dctx DecodeContext, vr bsonrw.Valu
452
466
if err = vr .ReadNull (); err != nil {
453
467
return err
454
468
}
469
+ case bsontype .Undefined :
470
+ if err = vr .ReadUndefined (); err != nil {
471
+ return err
472
+ }
455
473
default :
456
474
return fmt .Errorf ("cannot decode %v into a primitive.Symbol" , vrType )
457
475
}
@@ -474,6 +492,8 @@ func (DefaultValueDecoders) BinaryDecodeValue(dc DecodeContext, vr bsonrw.ValueR
474
492
data , subtype , err = vr .ReadBinary ()
475
493
case bsontype .Null :
476
494
err = vr .ReadNull ()
495
+ case bsontype .Undefined :
496
+ err = vr .ReadUndefined ()
477
497
default :
478
498
return fmt .Errorf ("cannot decode %v into a Binary" , vrType )
479
499
}
@@ -536,6 +556,10 @@ func (dvd DefaultValueDecoders) ObjectIDDecodeValue(dc DecodeContext, vr bsonrw.
536
556
if err = vr .ReadNull (); err != nil {
537
557
return err
538
558
}
559
+ case bsontype .Undefined :
560
+ if err = vr .ReadUndefined (); err != nil {
561
+ return err
562
+ }
539
563
default :
540
564
return fmt .Errorf ("cannot decode %v into an ObjectID" , vrType )
541
565
}
@@ -557,6 +581,8 @@ func (DefaultValueDecoders) DateTimeDecodeValue(dc DecodeContext, vr bsonrw.Valu
557
581
dt , err = vr .ReadDateTime ()
558
582
case bsontype .Null :
559
583
err = vr .ReadNull ()
584
+ case bsontype .Undefined :
585
+ err = vr .ReadUndefined ()
560
586
default :
561
587
return fmt .Errorf ("cannot decode %v into a DateTime" , vrType )
562
588
}
@@ -574,12 +600,21 @@ func (DefaultValueDecoders) NullDecodeValue(dc DecodeContext, vr bsonrw.ValueRea
574
600
return ValueDecoderError {Name : "NullDecodeValue" , Types : []reflect.Type {tNull }, Received : val }
575
601
}
576
602
577
- if vrType := vr .Type (); vrType != bsontype .Null {
578
- return fmt .Errorf ("cannot decode %v into a Null" , vrType )
603
+ var err error
604
+ switch vrType := vr .Type (); vrType {
605
+ case bsontype .Undefined :
606
+ err = vr .ReadUndefined ()
607
+ case bsontype .Null :
608
+ err = vr .ReadNull ()
609
+ default :
610
+ return fmt .Errorf ("cannot decode %v into a Null" , vr .Type ())
579
611
}
580
612
613
+ if err != nil {
614
+ return err
615
+ }
581
616
val .Set (reflect .ValueOf (primitive.Null {}))
582
- return vr . ReadNull ()
617
+ return nil
583
618
}
584
619
585
620
// RegexDecodeValue is the ValueDecoderFunc for Regex.
@@ -595,6 +630,8 @@ func (DefaultValueDecoders) RegexDecodeValue(dc DecodeContext, vr bsonrw.ValueRe
595
630
pattern , options , err = vr .ReadRegex ()
596
631
case bsontype .Null :
597
632
err = vr .ReadNull ()
633
+ case bsontype .Undefined :
634
+ err = vr .ReadUndefined ()
598
635
default :
599
636
return fmt .Errorf ("cannot decode %v into a Regex" , vrType )
600
637
}
@@ -620,6 +657,8 @@ func (DefaultValueDecoders) DBPointerDecodeValue(dc DecodeContext, vr bsonrw.Val
620
657
ns , pointer , err = vr .ReadDBPointer ()
621
658
case bsontype .Null :
622
659
err = vr .ReadNull ()
660
+ case bsontype .Undefined :
661
+ err = vr .ReadUndefined ()
623
662
default :
624
663
return fmt .Errorf ("cannot decode %v into a DBPointer" , vrType )
625
664
}
@@ -644,6 +683,8 @@ func (DefaultValueDecoders) TimestampDecodeValue(dc DecodeContext, vr bsonrw.Val
644
683
t , incr , err = vr .ReadTimestamp ()
645
684
case bsontype .Null :
646
685
err = vr .ReadNull ()
686
+ case bsontype .Undefined :
687
+ err = vr .ReadUndefined ()
647
688
default :
648
689
return fmt .Errorf ("cannot decode %v into a Timestamp" , vrType )
649
690
}
@@ -667,6 +708,8 @@ func (DefaultValueDecoders) MinKeyDecodeValue(dc DecodeContext, vr bsonrw.ValueR
667
708
err = vr .ReadMinKey ()
668
709
case bsontype .Null :
669
710
err = vr .ReadNull ()
711
+ case bsontype .Undefined :
712
+ err = vr .ReadUndefined ()
670
713
default :
671
714
return fmt .Errorf ("cannot decode %v into a MinKey" , vr .Type ())
672
715
}
@@ -690,6 +733,8 @@ func (DefaultValueDecoders) MaxKeyDecodeValue(dc DecodeContext, vr bsonrw.ValueR
690
733
err = vr .ReadMaxKey ()
691
734
case bsontype .Null :
692
735
err = vr .ReadNull ()
736
+ case bsontype .Undefined :
737
+ err = vr .ReadUndefined ()
693
738
default :
694
739
return fmt .Errorf ("cannot decode %v into a MaxKey" , vr .Type ())
695
740
}
@@ -714,6 +759,8 @@ func (dvd DefaultValueDecoders) Decimal128DecodeValue(dctx DecodeContext, vr bso
714
759
d128 , err = vr .ReadDecimal128 ()
715
760
case bsontype .Null :
716
761
err = vr .ReadNull ()
762
+ case bsontype .Undefined :
763
+ err = vr .ReadUndefined ()
717
764
default :
718
765
return fmt .Errorf ("cannot decode %v into a primitive.Decimal128" , vr .Type ())
719
766
}
@@ -755,6 +802,11 @@ func (dvd DefaultValueDecoders) JSONNumberDecodeValue(dc DecodeContext, vr bsonr
755
802
return err
756
803
}
757
804
val .SetString ("" )
805
+ case bsontype .Undefined :
806
+ if err := vr .ReadUndefined (); err != nil {
807
+ return err
808
+ }
809
+ val .SetString ("" )
758
810
default :
759
811
return fmt .Errorf ("cannot decode %v into a json.Number" , vrType )
760
812
}
@@ -787,6 +839,12 @@ func (dvd DefaultValueDecoders) URLDecodeValue(dc DecodeContext, vr bsonrw.Value
787
839
}
788
840
val .Set (reflect .ValueOf (url.URL {}))
789
841
return nil
842
+ case bsontype .Undefined :
843
+ if err := vr .ReadUndefined (); err != nil {
844
+ return err
845
+ }
846
+ val .Set (reflect .ValueOf (url.URL {}))
847
+ return nil
790
848
default :
791
849
return fmt .Errorf ("cannot decode %v into a *url.URL" , vrType )
792
850
}
@@ -935,6 +993,9 @@ func (dvd DefaultValueDecoders) ArrayDecodeValue(dc DecodeContext, vr bsonrw.Val
935
993
case bsontype .Null :
936
994
val .Set (reflect .Zero (val .Type ()))
937
995
return vr .ReadNull ()
996
+ case bsontype .Undefined :
997
+ val .Set (reflect .Zero (val .Type ()))
998
+ return vr .ReadUndefined ()
938
999
default :
939
1000
return fmt .Errorf ("cannot decode %v into an array" , vrType )
940
1001
}
@@ -1200,6 +1261,12 @@ func (dvd DefaultValueDecoders) CodeWithScopeDecodeValue(dc DecodeContext, vr bs
1200
1261
}
1201
1262
val .Set (reflect .ValueOf (primitive.CodeWithScope {}))
1202
1263
return nil
1264
+ case bsontype .Undefined :
1265
+ if err := vr .ReadUndefined (); err != nil {
1266
+ return err
1267
+ }
1268
+ val .Set (reflect .ValueOf (primitive.CodeWithScope {}))
1269
+ return nil
1203
1270
default :
1204
1271
return fmt .Errorf ("cannot decode %v into a primitive.CodeWithScope" , vrType )
1205
1272
}
0 commit comments