Example usage for com.mongodb DBCollection find

List of usage examples for com.mongodb DBCollection find

Introduction

In this page you can find the example usage for com.mongodb DBCollection find.

Prototype

public DBCursor find() 

Source Link

Document

Select all documents in collection and get a cursor to the selected documents.

Usage

From source file:controllers.FilterController.java

License:Apache License

public static Statistics getCollectionStatistics(String name) {
    final PersistenceLayer pl = Configurator.getDefaultConfigurator().getPersistence();
    BasicDBObject aggregation = null;/*  w  w  w .j  av  a 2  s  . co m*/

    DBCollection collection = pl.getDB().getCollection("statistics_" + name);
    if (collection.find().count() != 0) {
        aggregation = (BasicDBObject) collection.findOne().get("value");
    }

    if (aggregation == null) {
        final NumericAggregationJob job = new NumericAggregationJob(name, "size");
        job.setType(OutputType.REPLACE);
        job.setOutputCollection("statistics_" + name);
        final MapReduceOutput output = job.execute();

        if (output != null) {
            aggregation = (BasicDBObject) collection.findOne().get("value");
        }
    }

    return getStatisticsFromResult(aggregation);
}

From source file:dao.CocinaDAO.java

public List<Mensaje> getMensajes() {
    int estado;//from w w w  . ja va 2 s . c  o  m
    List<Mensaje> mensajes = null;
    Mensaje mensaje = null;
    ConexionMLab con = new ConexionMLab();
    MongoClient mongo = con.getConexion();
    try {
        DB db = mongo.getDB("pizzaplaneta");
        DBCollection coleccion = db.getCollection("pedido");
        DBCursor cursor = coleccion.find();
        mensajes = new ArrayList<>();
        while (cursor.hasNext()) {
            DBObject dbo = cursor.next();
            BasicDBList dbo1 = (BasicDBList) dbo.get("estados");
            DBObject est = (DBObject) (dbo1.get(dbo1.size() - 1));
            estado = (Integer) est.get("id");
            if (estado == 1 || estado == 0) {
                mensaje = new Mensaje((String) est.get("fechaHora"), estado, (Integer) dbo.get("_id"));
                mensajes.add(mensaje);
            }

        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        mongo.close();
    }
    return mensajes;

}

From source file:Dao.DaoFunc.java

public DBCursor get() {
    DBCollection col = db.getCollection("funcionario");
    DBCursor cursor = col.find();
    return cursor;

}

From source file:db.Storage.java

public DBCursor findAll(DBCollection table) {
    // return cursor = table.find();
    return table.find();
}

From source file:dbOld.Storage.java

public DBCursor findAll(DBCollection table) {
    return table.find();
}

From source file:de.belaso.mongolyn.ui.RepositoryConnector.java

License:Open Source License

@Override
public IStatus performQuery(TaskRepository taskRepository, IRepositoryQuery query, TaskDataCollector collector,
        ISynchronizationSession session, IProgressMonitor monitor) {
    try {/*from   w  ww.ja v a  2s  . c  o m*/
        DBCollection dbCollection = MongolynUtils.getDBCollection(taskRepository);
        DBCursor dbCursor = dbCollection.find();
        while (dbCursor.hasNext()) {
            DBObject dbObject = dbCursor.next();
            TaskData taskData = new TaskData(getTaskDataHandler().getAttributeMapper(taskRepository), KIND,
                    taskRepository.getRepositoryUrl(), dbObject.get("_id").toString());
            taskData.setPartial(false);
            taskData.setVersion("1");
            getTaskDataHandler().initializeTaskData(taskRepository, taskData, null, monitor);
            for (String key : dbObject.keySet()) {
                if (!"_id".equals(key))
                    taskData.getRoot().getAttribute(key.replace('_', '.'))
                            .setValue(dbObject.get(key).toString());
            }
            collector.accept(taskData);
        }
    } catch (CoreException coreException) {
        // nothing to do
    }
    return Status.OK_STATUS;
}

From source file:de.flapdoodle.mongoom.datastore.Datastore.java

License:Apache License

@Override
public <T> List<T> find(Class<T> entityClass) {
    IEntityTransformation<T> converter = _transformations.transformation(entityClass);
    DBCollection dbCollection = _db.getCollection(converter.collection().name());
    DBCursor dbcursor = dbCollection.find();

    List<T> ret = Lists.newArrayList();
    while (dbcursor.hasNext()) {
        ret.add(converter.asEntity(dbcursor.next()));
    }/*from   w w  w .j  a  va 2s  .com*/
    return ret;
}

From source file:de.unimannheim.infor.swt.uim.actions.MogoDBCreate.java

License:Open Source License

public static void Packagedocumentinsert(String id, String FQN, String name, String container) {

    try {/*  w w  w.j av a 2s .c om*/
        MongoClient mongoClient = new MongoClient(mdlocalhost, mdport);
        DB db = mongoClient.getDB(tmtextdb);
        boolean auth = db.authenticate(tmtextuser, tmtextpassword.toCharArray());
        DBCollection collection = db.getCollection("package");
        DBCursor cursor = collection.find();
        BasicDBObject document = new BasicDBObject();
        document.put("MySQLid", id);
        document.put("FQN", FQN);
        document.put("name", name);
        document.put("container", container);
        collection.insert(document);

    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (MongoException e) {
        e.printStackTrace();
    }
}

From source file:de.unimannheim.infor.swt.uim.actions.MogoDBCreate.java

License:Open Source License

public static void Deepmodeldocumentinsert(int id, int p_id, String FQN, String name, String container) {
    mdlocalhost = Login.tmtexthostx();//from  www . j ava 2 s . co m
    mdport = Integer.valueOf(Login.tmtextportx());
    tmtextdb = Login.tmtextdbx();
    tmtextuser = Login.tmtextuserx();
    tmtextpassword = Login.tmtextpasswordx();
    try {

        clearmongodb();
        MongoClient mongoClient = new MongoClient(mdlocalhost, mdport);
        DB db = mongoClient.getDB(tmtextdb);
        boolean auth = db.authenticate(tmtextuser, tmtextpassword.toCharArray());
        DBCollection collection = db.getCollection("deepmodel");
        DBCursor cursor = collection.find();
        BasicDBObject document = new BasicDBObject();
        document.put("MySQLid", id);
        document.put("p_id", p_id);
        document.put("FQN", FQN);
        document.put("name", name);
        document.put("container", container);
        collection.insert(document);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (MongoException e) {
        e.printStackTrace();
    }
}

From source file:de.unimannheim.infor.swt.uim.actions.MogoDBCreate.java

License:Open Source License

public static void Leveldocumentinsert(int id, String FQN, String name, String container, int number) {
    try {/*from  w w w  .  ja v  a  2 s . com*/

        MongoClient mongoClient = new MongoClient(mdlocalhost, mdport);
        DB db = mongoClient.getDB(tmtextdb);
        boolean auth = db.authenticate(tmtextuser, tmtextpassword.toCharArray());
        DBCollection collection = db.getCollection("level");
        DBCursor cursor = collection.find();
        BasicDBObject document = new BasicDBObject();
        document.put("MySQLid", id);
        document.put("FQN", FQN);
        document.put("name", name);
        document.put("container", container);
        document.put("number", number);
        collection.insert(document);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (MongoException e) {
        e.printStackTrace();
    }
}