11package dev .mongocamp .driver .mongodb .bson
22
3- import java .math .BigInteger
4- import java .time .{ LocalDate , LocalDateTime , ZoneId }
5- import java .util .Date
6-
73import org .mongodb .scala .Document
84import org .mongodb .scala .bson .BsonArray .fromIterable
95import org .mongodb .scala .bson .{ ObjectId , _ }
106
11- import scala .jdk .CollectionConverters ._
7+ import java .math .BigInteger
8+ import java .time .{ LocalDate , LocalDateTime , ZoneId }
9+ import java .util .Date
1210import scala .collection .mutable
11+ import scala .jdk .CollectionConverters ._
1312import scala .util .matching .Regex
1413
1514object BsonConverter {
@@ -73,18 +72,22 @@ object BsonConverter {
7372 }
7473 val mutableDoc = org.mongodb.scala.bson.collection.mutable.Document .apply(relatedDocument.toJson())
7574 document.put(relation, mutableDoc)
76- if (root.isEmpty)
75+ if (root.isEmpty) {
7776 updateDocumentValueInternal(mutableDoc, newKey, value, Some (document))
78- else
77+ }
78+ else {
7979 updateDocumentValueInternal(mutableDoc, newKey, value, root)
80+ }
8081
8182 }
8283 else {
8384 document.put(key, toBson(value))
84- if (root.isEmpty)
85+ if (root.isEmpty) {
8586 document
86- else
87+ }
88+ else {
8789 root.get
90+ }
8891 }
8992
9093 var converterPlugin : AbstractConverterPlugin = new BaseConverterPlugin ()
@@ -93,10 +96,12 @@ object BsonConverter {
9396 value match {
9497 case bsonValue : BsonValue => bsonValue
9598 case option : Option [Any ] =>
96- if (option.isDefined)
99+ if (option.isDefined) {
97100 toBson(option.get)
98- else
101+ }
102+ else {
99103 BsonNull ()
104+ }
100105 case v : Any if converterPlugin.hasCustomClass(v) =>
101106 converterPlugin.toBson(v)
102107 case b : Boolean => BsonBoolean (b)
@@ -174,7 +179,10 @@ object BsonConverter {
174179 value match {
175180 case d : Document =>
176181 result.+= (key -> asMap(d))
177- case _ => result.+= (key -> value)
182+ case ld : List [Document ] =>
183+ result.+= (key -> ld.map(d => asMap(d)))
184+ case _ =>
185+ result.+= (key -> value)
178186 }
179187 }
180188 result.toMap
0 commit comments