diff --git a/package.json b/package.json index a0ab16d..fb25d6e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name" : "mongodb-driver", "organization" : "dev.mongocamp", - "version" : "2.6.6.snapshot", + "version" : "2.6.6", "author" : "info@mongocamp.dev", "license" : "Apache-2.0", "repository" : { diff --git a/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala b/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala index 6421e17..a2f6c0d 100644 --- a/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala +++ b/src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala @@ -2,12 +2,13 @@ package dev.mongocamp.driver.mongodb.bson import org.mongodb.scala.Document import org.mongodb.scala.bson.BsonArray.fromIterable -import org.mongodb.scala.bson.{ ObjectId, _ } +import org.mongodb.scala.bson.{ObjectId, _} import java.math.BigInteger -import java.time.{ LocalDate, LocalDateTime, ZoneId } +import java.time.{LocalDate, LocalDateTime, ZoneId} import java.util.Date import scala.collection.mutable +import scala.concurrent.duration.Duration import scala.jdk.CollectionConverters._ import scala.util.matching.Regex @@ -22,7 +23,7 @@ object BsonConverter { def lastKeyFromRelation(key: String): String = key.substring(key.lastIndexOf(DocumentKeyDivider) + 1) - def documentValueOption(document: Document, key: String): Option[Any] = + def documentValueOption(document: Document, key: String): Option[Any] = { if (hasRelation(key)) { val newKey = newKeyFromRelation(key) val relation = relationKey(key) @@ -36,13 +37,17 @@ object BsonConverter { None } } - else + else { None + } } - else if (document.contains(key)) + else if (document.contains(key)) { Some(fromBson(document(key))) - else + } + else { None + } + } def updateDocumentValue(document: Document, key: String, value: Any): Document = { val doc = org.mongodb.scala.bson.collection.mutable.Document(document.toJson()) @@ -110,6 +115,7 @@ object BsonConverter { case bytes: Array[Byte] => BsonBinary(bytes) case r: Regex => BsonRegularExpression(r) case d: Date => BsonDateTime(d) + case d: Duration => BsonString(d.toString) case ld: LocalDate => BsonDateTime(Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant)) case ldt: LocalDateTime =>