Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MongoDb: How to save directly from json
Mongo mongo = new Mongo("127.0.0.1",27017);
DB db = mongo.getDB("yabe");
DBCollection collection = db.getCollection("pt");
DBCursor csr = collection.find();
for (DBObject dbObject : csr) {
System.out.println(dbObject);
}
WriteResult save = collection.save(new BasicDBObject() {{
this.append("user", 333);
}});
save = collection.save(new BasicDBObject() {{
this.append("user", "ikeda");
}});
System.out.println(save.toString());
WSRequest url = play.libs.WS.url("https://api.github.com/gists/958406");
final HttpResponse httpResponse = url.get();
System.out.println(httpResponse.getString());
final Object parse = JSON.parse(httpResponse.getString().replaceAll("\\.", "_"));
collection.save((DBObject) parse);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment