Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFS.findOne()


        // Optional bucket, default is "fs"
        String bucket = jsonObject.getString("bucket", GridFS.DEFAULT_BUCKET);
        GridFS files = new GridFS(db, bucket);

        GridFSDBFile file = files.findOne(objectId);
        if (file == null) {
            sendError(message, "File does not exist: " + objectId.toString());
            return;
        }
View Full Code Here


  }

  public static byte[] getFile(String fileName) {
    try {
      GridFS fs = new GridFS(db());
      GridFSDBFile out = fs.findOne(new BasicDBObject("_id", fileName));
      ByteArrayOutputStream temp = new ByteArrayOutputStream();
      out.writeTo(temp);
      return temp.toByteArray();
    } catch (Exception e) {
      // quiet
View Full Code Here

                    "Database with dbName [ " + dbName + "] does not exist");
            }
            Object docId = JSON.parse(_id);
            BasicDBObject objectId = new BasicDBObject("_id", docId);
            GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
            GridFSDBFile gridFSDBFile = gridFS.findOne(objectId);
            String tempDir = System.getProperty("java.io.tmpdir");
            tempFile = new File(tempDir + "/" + gridFSDBFile.getFilename());
            gridFSDBFile.writeTo(tempFile);

        } catch (MongoException m) {
View Full Code Here

            }

            GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
            Object docId = JSON.parse(_id);
            BasicDBObject objectId = new BasicDBObject("_id", docId);
            gridFSDBFile = gridFS.findOne(objectId);

            if (gridFSDBFile == null) {
                throw new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "Document does not exist !");
            }
View Full Code Here

            in.validate();

            String id = in.getId().toString();
            logger.debug("GridFS in: {}", in);
            logger.debug("Document created with id: {}", id);
            GridFSDBFile out = gridFS.findOne(in.getFilename());
            logger.debug("GridFS from findOne: {}", out);
            out = gridFS.findOne(new ObjectId(id));
            logger.debug("GridFS from findOne: {}", out);
            Assert.assertEquals(out.getId(), in.getId());
            ids.add(id);
View Full Code Here

            String id = in.getId().toString();
            logger.debug("GridFS in: {}", in);
            logger.debug("Document created with id: {}", id);
            GridFSDBFile out = gridFS.findOne(in.getFilename());
            logger.debug("GridFS from findOne: {}", out);
            out = gridFS.findOne(new ObjectId(id));
            logger.debug("GridFS from findOne: {}", out);
            Assert.assertEquals(out.getId(), in.getId());
            ids.add(id);
        }
View Full Code Here

                && (operation == Operation.INSERT || operation == Operation.UPDATE)) {
            if (objectId == null) {
                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());
                object = file;
            } else {
                logger.error("Cannot find file from id: {}", objectId);
View Full Code Here

                    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);
                            } else {
                              logger.debug("Last entry for initial import of {} - add timestamp: {}", collection.getFullName(), timestamp);
                              lastId = addInsertToStream(timestamp, file);
View Full Code Here

            String id = in.getId().toString();
            logger.debug("GridFS in: {}", in);
            logger.debug("Document created with id: {}", id);

            GridFSDBFile out = gridFS.findOne(in.getFilename());
            logger.debug("GridFS from findOne: {}", out);
            out = gridFS.findOne(new ObjectId(id));
            logger.debug("GridFS from findOne: {}", out);
            Assert.assertEquals(out.getId(), in.getId());
View Full Code Here

            logger.debug("GridFS in: {}", in);
            logger.debug("Document created with id: {}", id);

            GridFSDBFile out = gridFS.findOne(in.getFilename());
            logger.debug("GridFS from findOne: {}", out);
            out = gridFS.findOne(new ObjectId(id));
            logger.debug("GridFS from findOne: {}", out);
            Assert.assertEquals(out.getId(), in.getId());

            createRiver();
            Thread.sleep(wait);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.