List of usage examples for com.mongodb DBCursor toArray
public List<DBObject> toArray()
From source file:org.opencb.cellbase.mongodb.db.network.PathwayMongoDBAdaptor.java
License:Apache License
@Override public String getPathways() { BasicDBObject query = new BasicDBObject(); BasicDBObject returnFields = new BasicDBObject(); returnFields.put("_id", 0); returnFields.put("name", 1); returnFields.put("displayName", 1); returnFields.put("subPathways", 1); returnFields.put("parentPathway", 1); BasicDBObject orderBy = new BasicDBObject(); orderBy.put("name", 1); DBCursor cursor = coll.find(query, returnFields).sort(orderBy); String result = cursor.toArray().toString(); cursor.close();//from w w w .ja v a2 s.c om return result; }
From source file:org.opencb.cellbase.mongodb.db.network.PathwayMongoDBAdaptor.java
License:Apache License
@Override public String getTree() { BasicDBObject query = new BasicDBObject(); query.put("parentPathway", "none"); BasicDBObject returnFields = new BasicDBObject(); returnFields.put("_id", 0); returnFields.put("name", 1); returnFields.put("displayName", 1); returnFields.put("subPathways", 1); BasicDBObject orderBy = new BasicDBObject(); orderBy.put("displayName", 1); DBCursor cursor = coll.find(query, returnFields).sort(orderBy); String result = cursor.toArray().toString(); cursor.close();// w w w. j a va 2 s.c o m return result; }
From source file:org.opencb.cellbase.mongodb.db.network.PathwayMongoDBAdaptor.java
License:Apache License
@Override public String getPathway(String pathwayId) { BasicDBObject query = new BasicDBObject(); query.put("name", pathwayId); BasicDBObject returnFields = new BasicDBObject(); returnFields.put("_id", 0); DBCursor cursor = coll.find(query, returnFields); String result = cursor.toArray().toString(); cursor.close();/*from w w w . jav a2 s. c o m*/ return result; }
From source file:org.opencb.cellbase.mongodb.db.network.PathwayMongoDBAdaptor.java
License:Apache License
@Override public String search(String searchBy, String searchText, boolean returnOnlyIds) { Pattern regex = Pattern.compile(searchText, Pattern.CASE_INSENSITIVE); BasicDBObject query = new BasicDBObject(); if (searchBy.equalsIgnoreCase("pathway")) { query.put("displayName", regex); } else {/*from w ww.ja v a 2 s .c o m*/ BasicDBObject query1 = new BasicDBObject("physicalEntities.params.displayName", regex); BasicDBObject query2 = new BasicDBObject("interactions.params.displayName", regex); ArrayList<BasicDBObject> queryList = new ArrayList<BasicDBObject>(); queryList.add(query1); queryList.add(query2); query.put("$or", queryList); } System.out.println("Query: " + query); BasicDBObject returnFields = new BasicDBObject(); returnFields.put("_id", 0); if (returnOnlyIds) { returnFields.put("name", 1); } DBCursor cursor = coll.find(query, returnFields); String result = cursor.toArray().toString(); cursor.close(); return result; }
From source file:tango.mongo.MongoUtils.java
License:Open Source License
public static float[] getFloatArray(DBCursor cur, String key) { List<DBObject> list = cur.toArray(); float[] res = new float[list.size()]; boolean field = false; for (int i = 0; i < list.size(); i++) { BasicDBObject o = ((BasicDBObject) list.get(i)); if (o.containsField(key)) { field = true;// w w w .j a va 2 s . com res[i] = (float) o.getDouble(key); } } return field ? res : null; }
From source file:tfg.mongoaccessservice.MongoResource.java
@GET @Path("/getworkflows") @Produces(MediaType.APPLICATION_JSON)//from ww w.j av a2 s . co m public Response getWork() { DBCursor obj = null; try { DB db = ConnectionFactory.getInstance().getConnection(); DBCollection coll = db.getCollection("mail"); obj = coll.find(); System.out.println(obj); } catch (UnknownHostException ex) { Logger.getLogger(MongoResource.class.getName()).log(Level.SEVERE, null, ex); } return Response.status(Response.Status.OK).entity(obj.toArray()).build(); }
From source file:v7cr.vaadin.DBCollectionContainer.java
License:Open Source License
private List<Object> initIds(DBCursor cursor) { List<DBObject> x = cursor.toArray(); List<Object> _ids = new ArrayList<Object>(x.size()); for (DBObject o : x) { _ids.add(o.get("_id")); }/* w w w. j a v a 2s. com*/ return _ids; }