[英]how to insert xml file data into mongodb database using java?
how can i insert xml file data/contents (which is already exist in a disk) into MongoDB database using java? 如何使用Java将xml文件数据/内容(磁盘中已经存在)插入MongoDB数据库?
please any one can resolve it. 请任何人都可以解决。
//Edited code //编辑代码
XmlMapper xmlMapper = new XmlMapper();
List entries = xmlMapper.readValue(new File("C:/Users/manish/Desktop/BaseX65/xml/books.xml"),List.class);
ObjectMapper jsonMapper = new ObjectMapper();
String json = jsonMapper.writeValueAsString(entries);
try
{
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("newdb");
DBCollection collection = db.getCollection("dummyColl");
DBObject dbObject = (DBObject)JSON.parse(json);
collection.insert(dbObject);
DBCursor cursorDocJSON = collection.find();
while (cursorDocJSON.hasNext()) {
System.out.println(cursorDocJSON.next());
}
}
List<DBObject> dbObject =(List<DBObject>) JSON.parse(json)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.