看起来很简单:A有一个JSON字符串,我想将它作为JSON文档存储在MongoDB中。
在Java驱动程序2.xx中,我可以使用com.mongodb.util.JSON.parse(String jsonString)
获取DBObject,然后将其存储在集合中。
在驱动程序3.0中,[[JSON.parse仍然给出DBObject,但是其余的API使用的是org.bson.Document类,它看起来与DBObject不兼容。
如何在驱动程序3.0版中执行此操作?Document myDoc = Document.parse(jsonString)
对象的导入是:
private Map<String, Object> map; private DBObject dbObject = new BasicDBObject(map); private Document document = Document.parse(jsonText);
与Document对象有所不同,默认情况下,当对象保留在mongo上时,它将不考虑所有null属性。同一个不与另外两个相同,在您的配置中默认不。希望对您有帮助...