@@ -2,12 +2,13 @@ package dev.mongocamp.driver.mongodb.bson
22
33import org .mongodb .scala .Document
44import org .mongodb .scala .bson .BsonArray .fromIterable
5- import org .mongodb .scala .bson .{ ObjectId , _ }
5+ import org .mongodb .scala .bson .{ObjectId , _ }
66
77import java .math .BigInteger
8- import java .time .{ LocalDate , LocalDateTime , ZoneId }
8+ import java .time .{LocalDate , LocalDateTime , ZoneId }
99import java .util .Date
1010import scala .collection .mutable
11+ import scala .concurrent .duration .Duration
1112import scala .jdk .CollectionConverters ._
1213import scala .util .matching .Regex
1314
@@ -22,7 +23,7 @@ object BsonConverter {
2223
2324 def lastKeyFromRelation (key : String ): String = key.substring(key.lastIndexOf(DocumentKeyDivider ) + 1 )
2425
25- def documentValueOption (document : Document , key : String ): Option [Any ] =
26+ def documentValueOption (document : Document , key : String ): Option [Any ] = {
2627 if (hasRelation(key)) {
2728 val newKey = newKeyFromRelation(key)
2829 val relation = relationKey(key)
@@ -36,13 +37,17 @@ object BsonConverter {
3637 None
3738 }
3839 }
39- else
40+ else {
4041 None
42+ }
4143 }
42- else if (document.contains(key))
44+ else if (document.contains(key)) {
4345 Some (fromBson(document(key)))
44- else
46+ }
47+ else {
4548 None
49+ }
50+ }
4651
4752 def updateDocumentValue (document : Document , key : String , value : Any ): Document = {
4853 val doc = org.mongodb.scala.bson.collection.mutable.Document (document.toJson())
@@ -110,6 +115,7 @@ object BsonConverter {
110115 case bytes : Array [Byte ] => BsonBinary (bytes)
111116 case r : Regex => BsonRegularExpression (r)
112117 case d : Date => BsonDateTime (d)
118+ case d : Duration => BsonString (d.toString)
113119 case ld : LocalDate =>
114120 BsonDateTime (Date .from(ld.atStartOfDay(ZoneId .systemDefault()).toInstant))
115121 case ldt : LocalDateTime =>
0 commit comments