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)))
}
JSON stringinstead of asub document. You have to create an associative array(javascript object) in order to insert a subDocument. otherwise it will just create it as aJSON string"char inside your string values, for whatever reason not related to Mongo.