mongodb java driver 3.0: how to store JSON document

For you problem, you have at least 3 solutions, lets see:

private Map<String, Object> map;

private DBObject dbObject = new BasicDBObject(map);

private Document document = Document.parse(jsonText);

The imports of objects are:

import java.util.Map;
import org.bson.Document;
import com.mongodb.DBObject;

There are a difference with Document object, by default it disconsider all null attributes when object is persisted on mongo. The same not ocorres with another two, in your configuration default not.

I hope helped you...


For Document use the parse() static helper:

Document myDoc = Document.parse(jsonString)