I am trying to insert a whole Java object into a MongoDB Collection using Java. I am getting following error:
Error :
Exception in t
You can convert your java object into json string using the gson library and then insert it in mongodb.
Eg:
Gson gson = new Gson();
String json = gson.toJson(Employee);
BasicDBObject basicDBObject = new BasicDBObject("Name", json );
DBCollection dbCollection = db.getCollection("NameColl");
dbCollection.save(basicDBObject);