import java.net.UnknownHostException; import com.mongodb.DB; import com.mongodb.DBAddress; import com.mongodb.DBObject; import com.mongodb.Mongo; import com.mongodb.gridfs.GridFS; import com.mongodb.gridfs.GridFSInputFile; public class Main { private static GridFS gridFs; private static void createFile(String filename, byte[] bytes) { GridFSInputFile newFile = gridFs.createFile(bytes); newFile.setFilename(filename); newFile.save(); } public static void main(String[] args) throws UnknownHostException { DB db = Mongo.connect(new DBAddress("localhost", "mydb")); gridFs = new GridFS(db, "myBucket"); // create some test files createFile("file1", "data1".getBytes()); createFile("file2", "data2".getBytes()); // gridFs.remove((String)null); // nothing happens // gridFs.remove((ObjectId)null); // nothing happens gridFs.remove((DBObject)null); // all files from bucket are removed } }