-1

I am trying to save an object with lists however, when I save it the document appears with "\", like that:

\"tags\":[\"java\",\"eclipse\",\"jdbc\",\"jpa\",\"hibernate\",\"jee\",\"jsp\",\"servlets\",\"taglibs\",\"tagfiles\",\"mvc\",\"ajax\",\"spring\",\"tomcat\"]

When I print my map instance with toString() the result is without those "\", however, when I print my BasicDBObject it returns me the result with "\"

public void save(Map<String, Object> mapInstance) {

    BasicDBObject document = new BasicDBObject(mapInstance);

    collection.insert(document);
}
slavoo
  • 5,798
  • 64
  • 37
  • 39
arthurfnsc
  • 915
  • 3
  • 13
  • 30

1 Answers1

1

MongoDB doesn't directly accepts strings of JSON. You need to parse those into BasicDBObjects first. You can do that with something like:

Object o = com.mongodb.util.JSON.parse(mapInstance);
DBObject dbObj = (DBObject) o;

collection.insert(dbObj);
Derick
  • 35,169
  • 5
  • 76
  • 99