Skip to content

Commit 901fb0d

Browse files
author
QuadStingray
committed
fix: recursive BsonConverter.asMap for List of Documents
Fix for Issue at MongoCamp Server MongoCamp/mongocamp-server#28
1 parent d1a0ea9 commit 901fb0d

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb-driver",
3-
"version": "2.4.9.snapshot",
3+
"version": "2.4.9",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/MongoCamp/mongodb-driver.git"

src/main/scala/dev/mongocamp/driver/mongodb/bson/BsonConverter.scala

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package dev.mongocamp.driver.mongodb.bson
22

3-
import java.math.BigInteger
4-
import java.time.{ LocalDate, LocalDateTime, ZoneId }
5-
import java.util.Date
6-
73
import org.mongodb.scala.Document
84
import org.mongodb.scala.bson.BsonArray.fromIterable
95
import 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
1210
import scala.collection.mutable
11+
import scala.jdk.CollectionConverters._
1312
import scala.util.matching.Regex
1413

1514
object 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

Comments
 (0)