Skip to content

Instantly share code, notes, and snippets.

@ikeike443
Created May 12, 2011 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikeike443/968206 to your computer and use it in GitHub Desktop.
Save ikeike443/968206 to your computer and use it in GitHub Desktop.
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