diff --git a/MongoDBLink.m b/MongoDBLink.m index ba39804..030c21a 100644 --- a/MongoDBLink.m +++ b/MongoDBLink.m @@ -275,11 +275,17 @@ serialize[{}] := JavaNew["com.mongodb.BasicDBObject"] serialize[_, x : $rulepattern] := Block[ - {newdbobj = JavaNew["com.mongodb.BasicDBObject"]}, + {newdbobj = JavaNew["com.mongodb.BasicDBObject"]}, Map[serialize[newdbobj, #] &, x]; newdbobj ] +serialize[_, x : { $rulepattern }] := Block[ + {newdblist = JavaNew["com.mongodb.BasicDBList"]}, + MapIndexed[newdblist@put[First[#2] - 1, serialize[#]]&, x]; + newdblist +] + (* $in, $nin, ... *) serialize[dbobj_, Rule["_id", {a_ -> b_}]] := dbobj@put["_id", serialize[dbobj, {a -> (ObjectId /@ b)}]] diff --git a/PacletInfo.m b/PacletInfo.m index 69a0036..637d24e 100644 --- a/PacletInfo.m +++ b/PacletInfo.m @@ -4,7 +4,7 @@ Paclet[ Name -> "MongoDBLink", - Version -> "0.1.1", + Version -> "0.1.2", MathematicaVersion -> "6+", Extensions -> { diff --git a/Tests.wlt b/Tests.wlt index db07077..edaa8f9 100644 --- a/Tests.wlt +++ b/Tests.wlt @@ -370,6 +370,14 @@ VerificationTest[ TestID->"ebd27ef8-953f-433f-9f13-976c2f07ec6c" ] +VerificationTest[ + MongoDBLink`Private`serialize[{"a" -> 1, "b" -> {{"b1" -> 1}}}]@toString[] + , + "{ \"a\" : 1 , \"b\" : [ { \"b1\" : 1}]}" + , + TestID->"aa43675c-c925-4450-b221-8cb964194447" +] + EndTestSection[] VerificationTest[