Created
October 8, 2013 13:53
-
-
Save ewnd9/6885044 to your computer and use it in GitHub Desktop.
export files from mongo gridfs
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
package com.ewnd9; | |
import java.util.List; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.UnknownHostException; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.DBCursor; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.Mongo; | |
import com.mongodb.MongoException; | |
import com.mongodb.gridfs.GridFS; | |
import com.mongodb.gridfs.GridFSDBFile; | |
import com.mongodb.gridfs.GridFSInputFile; | |
public class App { | |
public static void main(String[] args) { | |
String address = args[0]; | |
int port = Integer.parseInt(args[1]); | |
String dbName = args[2]; | |
String collection = args[3]; | |
String outputFolder = args[4]; | |
try { | |
Mongo mongo = new Mongo(address, port); | |
DB db = mongo.getDB(dbName); | |
GridFS gfsPhoto = new GridFS(db, collection); | |
List<GridFSDBFile> files = gfsPhoto.find(new BasicDBObject()); | |
for (GridFSDBFile file : files) { | |
file.writeTo(outputFolder + file.getId()); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Firstly thank you for your export example
how to import data using this file??