Created
May 12, 2011 09:03
-
-
Save ikeike443/968206 to your computer and use it in GitHub Desktop.
MongoDb: How to save directly from json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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