com.mongodb.gridfs.GridFS.findOne()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中com.mongodb.gridfs.GridFS.findOne()方法的一些代码示例,展示了GridFS.findOne()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridFS.findOne()方法的具体详情如下:
包路径:com.mongodb.gridfs.GridFS
类名称:GridFS
方法名:findOne

GridFS.findOne介绍

[英]Finds one file matching the given query.
[中]查找一个与给定查询匹配的文件。

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. /**
  2. * Finds one file matching the given objectId. Equivalent to findOne(objectId).
  3. *
  4. * @param objectId the objectId of the file stored on a server
  5. * @return a gridfs file
  6. * @throws com.mongodb.MongoException if the operation fails
  7. */
  8. public GridFSDBFile find(final ObjectId objectId) {
  9. return findOne(objectId);
  10. }

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. /**
  2. * Finds one file matching the given filename.
  3. *
  4. * @param filename the name of the file stored on a server
  5. * @return the gridfs db file
  6. * @throws com.mongodb.MongoException if the operation fails
  7. */
  8. public GridFSDBFile findOne(final String filename) {
  9. return findOne(new BasicDBObject("filename", filename));
  10. }

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. /**
  2. * Finds one file matching the given objectId.
  3. *
  4. * @param objectId the objectId of the file stored on a server
  5. * @return a gridfs file
  6. * @throws com.mongodb.MongoException if the operation fails
  7. */
  8. public GridFSDBFile findOne(final ObjectId objectId) {
  9. return findOne(new BasicDBObject("_id", objectId));
  10. }

代码示例来源:origin: org.mongodb/mongo-java-driver

  1. GridFS fs = getGridFS();
  2. String fn = args[i + 1];
  3. GridFSDBFile f = fs.findOne(fn);
  4. if (f == null) {
  5. System.err.println("can't find file: " + fn);
  6. GridFS fs = getGridFS();
  7. String fn = args[i + 1];
  8. GridFSDBFile f = fs.findOne(fn);
  9. if (f == null) {
  10. System.err.println("can't find file: " + fn);

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

  1. GridFSDBFile file = grid.findOne(new ObjectId(objectId));
  2. if (file != null) {
  3. logger.trace("Caught file: {} - {}", file.getId(), file.getFilename());

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

  1. DBObject object = cursor.next();
  2. if (object instanceof GridFSDBFile) {
  3. GridFSDBFile file = grid.findOne(new ObjectId(object.get(MongoDBRiver.MONGODB_ID_FIELD).toString()));
  4. if (cursor.hasNext()) {
  5. lastId = addInsertToStream(null, file);

代码示例来源:origin: org.mongodb/mongodb-driver

  1. /**
  2. * Finds one file matching the given objectId. Equivalent to findOne(objectId).
  3. *
  4. * @param objectId the objectId of the file stored on a server
  5. * @return a gridfs file
  6. * @throws com.mongodb.MongoException if the operation fails
  7. */
  8. public GridFSDBFile find(final ObjectId objectId) {
  9. return findOne(objectId);
  10. }

代码示例来源:origin: org.mongodb/mongodb-driver

  1. /**
  2. * Finds one file matching the given objectId.
  3. *
  4. * @param objectId the objectId of the file stored on a server
  5. * @return a gridfs file
  6. * @throws com.mongodb.MongoException if the operation fails
  7. */
  8. public GridFSDBFile findOne(final ObjectId objectId) {
  9. return findOne(new BasicDBObject("_id", objectId));
  10. }

代码示例来源:origin: org.mongodb/mongodb-driver

  1. /**
  2. * Finds one file matching the given filename.
  3. *
  4. * @param filename the name of the file stored on a server
  5. * @return the gridfs db file
  6. * @throws com.mongodb.MongoException if the operation fails
  7. */
  8. public GridFSDBFile findOne(final String filename) {
  9. return findOne(new BasicDBObject("filename", filename));
  10. }

代码示例来源:origin: org.craftercms/crafter-commons-mongo

  1. protected GridFSDBFile validateObject(final String storeName) throws FileNotFoundException {
  2. GridFSDBFile file = gridfs.findOne(storeName);
  3. if (file == null) {
  4. log.error("A file with name {} does not exists", storeName);
  5. throw new FileNotFoundException("File with file name " + storeName + " does not exist");
  6. }
  7. return file;
  8. }

代码示例来源:origin: org.craftercms/crafter-commons-mongo

  1. protected GridFSDBFile validateObject(final ObjectId fileId) throws FileNotFoundException {
  2. GridFSDBFile file = gridfs.findOne(fileId);
  3. if (file == null) {
  4. log.error("A file with id {} does not exists", fileId);
  5. throw new FileNotFoundException("File with file name " + fileId + " does not exist");
  6. }
  7. return file;
  8. }

代码示例来源:origin: org.apache.jackrabbit/oak-mongomk

  1. @Override
  2. public Long execute() throws Exception {
  3. GridFSDBFile gridFSDBFile = gridFS.findOne(new BasicDBObject("md5", blobId));
  4. if (gridFSDBFile == null) {
  5. throw new Exception("Blob does not exist");
  6. }
  7. return gridFSDBFile.getLength();
  8. }
  9. }

代码示例来源:origin: apache/incubator-wave

  1. @Override
  2. public AttachmentData getAttachment(AttachmentId attachmentId) {
  3. final GridFSDBFile attachment = attachmentGrid.findOne(attachmentId.serialise());
  4. return fileToAttachmentData(attachment);
  5. }

代码示例来源:origin: pl.edu.icm.synat/synat-core-services-impl

  1. @Override
  2. public GridFSDBFile findBinary(DBRef ref) {
  3. if (ref.getId() instanceof ObjectId) {
  4. ObjectId objectId = (ObjectId) ref.getId();
  5. return gridfsAccessor.getGridFs().findOne(objectId);
  6. } else {
  7. return gridfsAccessor.getGridFs().findOne(ref.getId().toString());
  8. }
  9. }

代码示例来源:origin: org.apache.jackrabbit/oak-mongomk

  1. private String saveBlob() throws IOException {
  2. BufferedInputStream bis = new BufferedInputStream(is);
  3. String md5 = calculateMd5(bis);
  4. GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", md5));
  5. if (gridFile != null) {
  6. is.close();
  7. return md5;
  8. }
  9. GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true);
  10. gridFSInputFile.save();
  11. return gridFSInputFile.getMD5();
  12. }

代码示例来源:origin: stackoverflow.com

  1. MongoClient client = new MongoClient();
  2. GridFS gridFS = new GridFS(client.getDB("test");
  3. GridFSInputFile in = gridFS.createFile(<insert bytes here>);
  4. in.put("meta", 5); // insert extra metadata here
  5. in.save();
  6. GridFSDBFile out = gridFS.findOne( new BasicDBObject( "_id" , in.getId() ) );
  7. System.out.println(out.get("meta")); // this will print 5

代码示例来源:origin: Cognifide/aet

  1. @Override
  2. public Artifact getArtifact(DBKey dbKey, String objectID) {
  3. Artifact artifact = null;
  4. GridFS gfs = getGridFS(dbKey);
  5. BasicDBObject query = new BasicDBObject();
  6. query.put(ID_FIELD_NAME, new ObjectId(objectID));
  7. GridFSDBFile file = gfs.findOne(query);
  8. if (file != null) {
  9. artifact = new Artifact(file.getInputStream(), file.getContentType());
  10. }
  11. return artifact;
  12. }

代码示例来源:origin: com.cognifide.aet/datastorage

  1. @Override
  2. public Artifact getArtifact(DBKey dbKey, String objectID) {
  3. Artifact artifact = null;
  4. GridFS gfs = getGridFS(dbKey);
  5. BasicDBObject query = new BasicDBObject();
  6. query.put(ID_FIELD_NAME, new ObjectId(objectID));
  7. GridFSDBFile file = gfs.findOne(query);
  8. if (file != null) {
  9. artifact = new Artifact(file.getInputStream(), file.getContentType());
  10. }
  11. return artifact;
  12. }

代码示例来源:origin: de.adorsys.cryptoutils/mongodbstoreconnection

  1. @Override
  2. public StorageMetadata getStorageMetadata(BucketPath bucketPath) {
  3. SPECIAL_LOGGER.debug("readmetadata " + bucketPath); // Dies LogZeile ist fuer den JUNIT-Tests StorageMetaDataTest
  4. LOGGER.debug("readmetadata " + bucketPath);
  5. GridFSBucket bucket = getGridFSBucket(bucketPath);
  6. checkBucketExists(bucket);
  7. GridFS gridFS = new GridFS(databaseDeprecated, bucketPath.getObjectHandle().getContainer());
  8. GridFSDBFile one = gridFS.findOne(bucketPath.getObjectHandle().getName());
  9. String jsonString = (String) one.getMetaData().get(STORAGE_METADATA_KEY);
  10. return gsonHelper.fromJson(jsonString);
  11. }

代码示例来源:origin: Kurento/kurento-java

  1. protected void refreshAttributesOnClose() {
  2. dbFile = ((MongoRepository) repository).getGridFS().findOne(getId());
  3. if (dbFile == null) {
  4. throw new KurentoException("Grid object not found for id " + getId());
  5. }
  6. state = State.STORED;
  7. attributes.setContentLength(dbFile.getLength());
  8. }

相关文章