Refine search
@SuppressWarnings("deprecation") // We know GridFS uses the old API. A new API version will be address later. private static GridFS getGridFS() throws Exception { if (gridFS == null) { gridFS = new GridFS(getMongo().getDB(db)); } return gridFS; }
DBCursor fileListCursor = fs.getFileList(); try { while (fileListCursor.hasNext()) { GridFS fs = getGridFS(); String fn = args[i + 1]; GridFSDBFile f = fs.findOne(fn); if (f == null) { System.err.println("can't find file: " + fn); GridFS fs = getGridFS(); String fn = args[i + 1]; GridFSInputFile f = fs.createFile(new File(fn)); f.save(); f.validate(); return; GridFS fs = getGridFS(); String fn = args[i + 1]; GridFSDBFile f = fs.findOne(fn); if (f == null) { System.err.println("can't find file: " + fn);
/** * Removes all files matching the given filename. * * @param filename the name of the file to be removed * @throws com.mongodb.MongoException if the operation fails */ public void remove(final String filename) { if (filename == null) { throw new IllegalArgumentException("filename can not be null"); } remove(new BasicDBObject("filename", filename)); }
if (ptsCollection.count() < 1000) { ptsCollection.createIndex(new BasicDBObject("id", 1)); persistentTimestamp = ptsCollection.findOne(new BasicDBObject("id", endpoint.getPersistentTSObject())); if (persistentTimestamp == null) { persistentTimestamp = new BasicDBObject("id", endpoint.getPersistentTSObject()); fromDate = new java.util.Date(); persistentTimestamp.put("timestamp", fromDate); file = endpoint.getGridFs().findOne(new BasicDBObject("_id", file.getId()));
/** * Finds one file matching the given objectId. * * @param objectId the objectId of the file stored on a server * @return a gridfs file * @throws com.mongodb.MongoException if the operation fails */ public GridFSDBFile findOne(final ObjectId objectId) { return findOne(new BasicDBObject("_id", objectId)); }
logger.info("MongoDBRiver is beginning initial import of " + collection.getFullName()); boolean inProgress = true; String lastId = null; if (logger.isTraceEnabled()) { logger.trace("Collection {} - count: {}", collection.getName(), safeCount(collection, timestamp.getClass())); .find(getFilterForInitialImport(definition.getMongoCollectionFilter(), lastId)) .sort(new BasicDBObject("_id", 1)); while (cursor.hasNext() && context.getStatus() == Status.RUNNING) { DBObject object = cursor.next(); GridFS grid = new GridFS(mongoClient.getDB(definition.getMongoDb()), definition.getMongoCollection()); cursor = grid.getFileList(); while (cursor.hasNext()) { DBObject object = cursor.next(); if (object instanceof GridFSDBFile) { GridFSDBFile file = grid.findOne(new ObjectId(object.get(MongoDBRiver.MONGODB_ID_FIELD).toString())); if (cursor.hasNext()) { lastId = addInsertToStream(null, file);
/** * Finds a list of files matching the given filename. * * @param filename the filename to look for * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final String filename) { return find(new BasicDBObject("filename", filename)); }
@Override public boolean save(Object id, String fileName, InputStream file) { pipelinefs.remove(new BasicDBObject(MongoDocument.MONGO_ID_KEY, id)); GridFSInputFile inputFile = pipelinefs.createFile(file, fileName); inputFile.put("_id", id); inputFile.save(); return true; }
String mystring = new String(); // an empty string GridFS gridFS = new GridFS(mongoTemplate.getDB(),"noteAndFile"); GridFSInputFile gfsFile = gridFS.createFile( new ByteArrayInputStream( mystring.getBytes() ) ); BasicDBObject meta = new BasicDBObject(); meta.put("comments","hi"); gfsFile.put("metadata",meta); gfsFile.save(); System.out.println(gfsFile.getId()); // gives me the _id of the object saved
@Override @Deprecated public void removeInactiveFiles() { BasicDBObject query = new BasicDBObject(); query.put(MongoPipelineReader.ACTIVE_KEY, Stage.Mode.INACTIVE.toString()); List<GridFSDBFile> list = pipelinefs.find(query); for(GridFSDBFile file : list) { pipelinefs.remove(file); } }
@Override public Artifact getArtifact(DBKey dbKey, String objectID) { Artifact artifact = null; GridFS gfs = getGridFS(dbKey); BasicDBObject query = new BasicDBObject(); query.put(ID_FIELD_NAME, new ObjectId(objectID)); GridFSDBFile file = gfs.findOne(query); if (file != null) { artifact = new Artifact(file.getInputStream(), file.getContentType()); } return artifact; }
entry.put(MongoDBRiver.OPLOG_OBJECT, object = new BasicDBObject(MongoDBRiver.MONGODB_ID_FIELD, objectId)); throw new NullPointerException(MongoDBRiver.MONGODB_ID_FIELD); GridFS grid = new GridFS(mongoShardClient.getDB(definition.getMongoDb()), collection); GridFSDBFile file = grid.findOne(new ObjectId(objectId)); if (file != null) { logger.trace("Caught file: {} - {}", file.getId(), file.getFilename());
GridFSInputFile gfsFile = endpoint.getGridFs().createFile(ins, filename, true); if (chunkSize != null && chunkSize > 0) { gfsFile.setChunkSize(chunkSize); gfsFile.setContentType(ct); gfsFile.setMetaData(dbObject); } else if ("remove".equals(operation)) { final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); endpoint.getGridFs().remove(filename); } else if ("findOne".equals(operation)) { final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); GridFSDBFile file = endpoint.getGridFs().findOne(filename); if (file != null) { exchange.getIn().setHeader(GridFsEndpoint.GRIDFS_METADATA, JSON.serialize(file.getMetaData())); DBCursor cursor; if (filename == null) { cursor = endpoint.getGridFs().getFileList(); } else { cursor = endpoint.getGridFs().getFileList(new BasicDBObject("filename", filename)); DBCursor cursor; if (filename == null) { cursor = endpoint.getGridFs().getFileList(); } else { cursor = endpoint.getGridFs().getFileList(new BasicDBObject("filename", filename));
@Override public void deleteAll() { documents.remove(new BasicDBObject()); documentfs.remove(new BasicDBObject()); }
private String saveBlob() throws IOException { BufferedInputStream bis = new BufferedInputStream(is); String md5 = calculateMd5(bis); GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", md5)); if (gridFile != null) { is.close(); return md5; } GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true); gridFSInputFile.save(); return gridFSInputFile.getMD5(); }
@Override public boolean deleteFile(Object id) { DBObject obj = new BasicDBObject(MongoDocument.MONGO_ID_KEY, id); if (pipelinefs.find(obj).size()==0) { return false; } pipelinefs.remove(obj); return true; } }
private static GridFSDBFile getMostRecentlyUploadedFile(GridFS gridFS, String filename) { DBObject queryByFilename = new BasicDBObject("filename", filename); DBObject sortByUploadDateDescending = new BasicDBObject("uploadDate", -1); DBCursor dbCursor = gridFS.getFileList(queryByFilename, sortByUploadDateDescending); return dbCursor.hasNext() ? getGridFSDBFileForDBObject(gridFS, dbCursor.next()) : null; }
public String save(InputStream is, String filename, Map<String, Object> attributes){ GridFSInputFile f = fs.createFile(is); f.setChunkSize(chunkSize); f.setFilename(filename); setAttributes(f, attributes); f.save(); return f.getId().toString(); }