Last active
August 29, 2015 14:02
-
-
Save kalharbi/ac181291ccf7e601927f to your computer and use it in GitHub Desktop.
Retrieve zip file from MongoDB GridFS and save it in a directory
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
MongoClient mongoClient = new MongoClient("localhost", 27017); | |
DB db = mongoClient.getDB("archives"); | |
GridFS gridGfs = new GridFS(db, "fs"); | |
// search by metadata | |
BasicDBObject query = new BasicDBObject("metadata.n", "myZipFile") | |
.append("metadata.ver", "1.2.6"); | |
GridFSDBFile zipFile = gridGfs.findOne(query); | |
File outFile = new File("/Users/Khalid/git/gists/file.zip"); | |
outFile.createNewFile(); | |
zipFile.writeTo(outFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment