2016-11-28 68 views
0

我想知道如何將情緒分析的JSON輸出存儲到mongoDB數據庫。事情是,情緒JSON輸出是DocumentSentiment,而monogoDB輸入必須是Document參數。這就是我所擁有的:Alchemy API和mongoDB

MongoCollection<Document> col2 = database.getCollection("test3"); 
col2.insertOne(sentiment); 

有人在Java中使用Alchemy和mongoDB時必須經歷過這個。

回答

0

我將構建一個文檔與值從你感興趣的情緒。

BasicDBObject document = new BasicDBObject(); 
document.put("text", mytext); 
document.put("score", sentiment.getSentiment().getScore()); 
document.put("type", sentiment.getSentiment().getType()); 
col2.insertOne(document);