List of usage examples for com.mongodb.gridfs GridFS find
public List<GridFSDBFile> find(final DBObject query, final DBObject sort)
From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBConnector.java
License:EUPL
/** * Gets the version of the <tt>filename</tt> with the latest uploaded date. * @param gridfs - GridFS client// ww w. java2s . c om * @param filename - filename to be searched for in the database * @return the version of the file identified by the provided filename with the latest uploaded date. */ private GridFSDBFile getLatestUploadedFile(final GridFS gridfs, final String filename) { return getFirst(gridfs.find(filename.trim(), new BasicDBObject("uploadDate", -1)), null); }
From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBConnector.java
License:EUPL
public void removeOpenAccessLink(final @Nullable String namespace, final String filename) { checkArgument(isNotBlank(filename), "Uninitialized or invalid filename"); final String namespace2 = trimToEmpty(namespace); final String filename2 = filename.trim(); final DB db = client().getDB(CONFIG_MANAGER.getDbName()); final GridFS gfsNs = isNotBlank(namespace2) ? new GridFS(db, namespace2) : new GridFS(db); final List<GridFSDBFile> files = gfsNs.find(new BasicDBObject("filename", filename2) .append(FILE_OPEN_ACCESS_LINK_PROP, new BasicDBObject("$exists", true)), new BasicDBObject("uploadDate", -1)); for (final GridFSDBFile file : files) { if (file.getMetaData() != null) { file.getMetaData().removeField(OPEN_ACCESS_LINK_ATTR); file.getMetaData().removeField(OPEN_ACCESS_DATE_ATTR); file.save();/*from w w w. j a v a 2s . c o m*/ } } /* ideally we want to use a cursor here, but the save() operation fails final DBCursor cursor = gfsNs.getFileList(new BasicDBObject("filename", filename2).append(FILE_OPEN_ACCESS_LINK_PROP, new BasicDBObject("$exists", true))); try { while (cursor.hasNext()) { final GridFSDBFile file = (GridFSDBFile) cursor.next(); if (file.getMetaData() != null) { file.getMetaData().removeField(OPEN_ACCESS_LINK_ATTR); file.getMetaData().removeField(OPEN_ACCESS_DATE_ATTR); // this fails file.save(); } } } finally { cursor.close(); } */ }