我正在使用 Scala、Play 框架和 Mongo scala 驱动程序来设置数据库。我有 json 数据来了,我想将它设置在数据库中,但我不知道如何格式化对象数组以便可以传递它。
这是 Json :
{
"dateCreationProcess":"2018-04-18T16:05:21.244Z",
"sci":false,
"nomEntreprise":"a",
"siren":"a",
"dateCreation":"20/04/2018",
"entreeRelation":"08/04/2018",
"secteur":"AGRICULTEUR PETITE EXPLOITATION",
"cotationBDF":"a",
"montantPrivileges":"a",
"fcc":"a",
"ca":"a",
"resultatBrut":"a",
"ebe":"a",
"totalBilan":"a",
"fp":"a",
"nbAssoc":"1",
"assoc":
[
{
"tiersAssoc":"a",
"nom":"a",
"prenom":"a",
"birthday":"19/04/2018"
},
{
"tiersAssoc":"b",
"nom":"b",
"prenom":"b",
"birthday":"20/04/2018"
}
],
"cotation":"a",
"fccAssociate":"a",
"ficp":"a",
"mntAcquisition":"",
"codePostal":"",
"typePret":"",
"mntFinance":"",
"mensualite":"",
"loyerPrevisionnel":""
}
如您所见,“assoc”是一个对象数组。对于我所做的所有其他领域:
val bsonDoc: Document = Document(
"userId" -> new BsonString(userId),
"processId" -> new BsonString(processId),
"done" -> false,
"sci" -> (uncompleteForm \ "sci").get.as[Boolean],
"nomEntreprise" -> (uncompleteForm \ "nomEntreprise").get.as[String],
"siren" -> (uncompleteForm \ "siren").get.as[String],
"dateCreation" -> (uncompleteForm \ "dateCreation").get.as[String],
"entreeRelation" -> (uncompleteForm \ "entreeRelation").get.as[String],
"secteur" -> (uncompleteForm \ "secteur").get.as[String],
"cotationBDF" -> (uncompleteForm \ "cotationBDF").get.as[String],
"montantPrivileges" -> (uncompleteForm \ "montantPrivileges").get.as[String],
"fcc" -> (uncompleteForm \ "fcc").get.as[String],
"ca" -> (uncompleteForm \ "ca").get.as[String],
"resultatBrut" -> (uncompleteForm \ "resultatBrut").get.as[String],
"ebe" -> (uncompleteForm \ "ebe").get.as[String],
"totalBilan" -> (uncompleteForm \ "totalBilan").get.as[String],
"fp" -> (uncompleteForm \ "fp").get.as[String],
"nbAssoc" -> (uncompleteForm \ "nbAssoc").get.as[String],
"cotation" -> (uncompleteForm \ "cotation").get.as[String],
"fccAssociate" -> (uncompleteForm \ "fccAssociate").get.as[String],
"ficp" -> (uncompleteForm \ "ficp").get.as[String],
"mntAcquisition" -> (uncompleteForm \ "mntAcquisition").get.as[String],
"codePostal" -> (uncompleteForm \ "codePostal").get.as[String],
"typePret" -> (uncompleteForm \ "typePret").get.as[String],
"mntFinance" -> (uncompleteForm \ "mntFinance").get.as[String],
"mensualite" -> (uncompleteForm \ "mensualite").get.as[String],
"loyerPrevisionnel" -> (uncompleteForm \ "loyerPrevisionnel").get.as[String]
)
如何在 Bson 文档中将其解析为可接受的?