Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactivemongo Insert (Map[String,String])

I've a MongoDB collection where I want to store documents like this:

{
    "_id" : ObjectId("52d14842ed0000ed0017cceb"),
    "details": {"name" : "Pankaj" , "email_id" :"[email protected]"}
}

But unfortunately here insert into mongo like this:

{
 "_id" : ObjectId("52d14842ed0000ed0017cceb"),
 "details" : { "name" : "\"Pankaj\"", "email_id" : "\"[email protected]\""} 
}

Why this slash coming into mongo! How to remove this slash?

In my code "details" store in Map[String,String]. And here is how I insert a document:

//BsonDocument
var document = BSONDocument()
details.foreach(e => {document = document.add(BSONDocument(e._1 -> BSONString(e._2)))
    }
like image 494
panky Avatar asked Dec 10 '25 05:12

panky


1 Answers

You need to convert what you need to insert into a BSONObject. Otherwise, it will be treated as a String.

like image 187
Luong Ba Linh Avatar answered Dec 11 '25 21:12

Luong Ba Linh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!