Example usage for com.mongodb.gridfs GridFS remove

List of usage examples for com.mongodb.gridfs GridFS remove

Introduction

In this page you can find the example usage for com.mongodb.gridfs GridFS remove.

Prototype

public void remove(final DBObject query) 

Source Link

Document

Removes all files matching the given query.

Usage

From source file:tango.mongo.ImageManager.java

License:Open Source License

private void transferFiles(String queryField, ObjectId queryValue, GridFS gfsSource, GridFS gfsDestination) {
    BasicDBObject query = new BasicDBObject(queryField, queryValue);
    List<GridFSDBFile> files = gfsSource.find(query); // FIXME charge tout en mmoire?
    for (GridFSDBFile file : files) {
        GridFSInputFile gfi = gfsDestination.createFile(file.getInputStream(), file.getFilename());
        gfi.put(queryField, queryValue);
        gfi.put("fileIdx", file.get("fileIdx"));
        gfi.put("fileType", file.get("fileType"));
        gfi.put("pixelDepth", file.get("pixelDepth"));
        gfi.put("unit", file.get("unit"));
        gfi.save();/*from   www  . j  a va  2  s. co  m*/
        if (gfi != null)
            try {
                gfi.getOutputStream().close();
            } catch (IOException ex) {
                Logger.getLogger(ImageManager.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
    gfsSource.remove(query);
}