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)))
}
You need to convert what you need to insert into a BSONObject. Otherwise, it will be treated as a String.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With