/** * Converts this cursor to an array. * * @return an array of elements * @throws MongoException if failed */ public List<DBObject> toArray() { return toArray(Integer.MAX_VALUE); }
public List<DBObject> getResultsInDescendingOrderByDate(int limit) { List<DBObject> myList = null; DBCursor myCursor=myCollection.find().sort(new BasicDBObject("date",-1)).limit(10); myList = myCursor.toArray(); return myList; }
/** * Converts this cursor to an array. * * @return an array of elements * @throws MongoException if failed */ public List<DBObject> toArray() { return toArray(Integer.MAX_VALUE); }
@Override public List<DBObject> toArray() { return cursor.toArray(); }
@Override public List<DBObject> toArray() { return cursor.toArray(); }
import javax.ws.rs.*; @Path("/applicationInitiatorService/") public class ApplicationInitiatorService { @GET @Path("/addContact") @Produces("application/json") public Response add_Contact() { DBCursor cursor = ApplicationInitiatorFactory.getApplicationinitiator().add_record(getcCollection); return Response.status(200).entity(cursor.toArray()).build(); } }
@Override public List<DBObject> toArray(int max) { return cursor.toArray(max); }
@Override public List<DBObject> toArray(int max) { return cursor.toArray(max); }
public List<DBObject> find(String name, DBObject where) { try { DBCursor c = getCollection(name).find(where); if (c != null) { List<DBObject> list = new ArrayList<DBObject>(); list = c.toArray(); return list; } } catch (Exception e) { logger.error("find where occur error", e); } return null; }
BasicDBObject fields = new BasicDBObject(); fields.put("name", true); BasicDBObject query = new BasicDBObject(); query.put("id", 13); query.put("dept_id", 23); DBCursor find = mongoTemplate.getCollection("example").find(query, select); List<DBObject> list = find.toArray(); List<String> names = list.stream().map(o -> String.valueOf(o.get("name"))).collect(Collectors.toList());
DBCursor dbCursor = mongoOperations.getCollection(RESOURCE_COLLECTION_NAME).find().sort(new BasicDBObject("_id", 1)); List<DBObject> dbObjects = dbCursor.toArray(); List<Map> items = new ArrayList<Map>(dbCursor.length()); for (DBObject dbObject : dbObjects) { Map map = dbObject.toMap(); items.add(dbObject.toMap()); }
@Override public Map<String, Object> readAll(String deviceId) { BasicDBObject metricsQuery = new BasicDBObject(); metricsQuery.put(FIELD_DEVICE_ID, deviceId); return mongo.getDB(db).getCollection(collection).find(metricsQuery).toArray().stream().collect( toMap(metric -> (String )metric.get(FIELD_METRIC), metric -> metric.get("value")) ); }
@Override @SuppressWarnings("unchecked") public List<Scope> getAllScopes() { List<Scope> list = new ArrayList<Scope>(); DBCollection coll = db.getCollection(SCOPE_COLLECTION_NAME); List<DBObject> result = coll.find().toArray(); for (DBObject obj : result) { Map<String, Object> mapLoaded = obj.toMap(); Scope scope = Scope.loadFromMap(mapLoaded); list.add(scope); } return list; }
@Override public void updateAccessTokenValidStatus(String accessToken, boolean valid) { BasicDBObject dbObject = new BasicDBObject(); dbObject.put("token", accessToken); DBCollection coll = db.getCollection(ACCESS_TOKEN_COLLECTION_NAME); List<DBObject> list = coll.find(dbObject).toArray(); if (list.size() > 0) { DBObject newObject = list.get(0); newObject.put("valid", valid); coll.findAndModify(dbObject, newObject); } }
protected synchronized void _dropIndexes() { List<DBObject> indexes = fongoDb.getCollection("system.indexes").find().toArray(); // Two step for no concurrent modification exception for (DBObject index : indexes) { dropIndexes(index.get("name").toString()); } }
@Override public DBObject createResult(DBCollection coll) { BasicDBList list = new BasicDBList(); list.addAll(coll.find().toArray()); return list; } };
@Override public void removeUserTokens(String userId) { BasicDBObject dbObject = new BasicDBObject(); // TODO: add indexes dbObject.put(USER_ID, userId); DBCollection coll = db.getCollection(ACCESS_TOKEN_COLLECTION_NAME); List<DBObject> list = coll.find(dbObject).toArray(); for (DBObject object : list) { coll.findAndModify(dbObject, object); coll.remove(object); } }
/** * @param coll * @param object * @return */ @Override public DBCollection apply(DBCollection coll, DBObject object) { List<DBObject> objects = coll.find().skip(((Number) object.get(getKeyword())).intValue()).toArray(); return dropAndInsert(coll, objects); }
/** * @param coll * @param object * @return */ @Override public DBCollection apply(DBCollection coll, DBObject object) { List<DBObject> objects = coll.find().limit(((Number) object.get(getKeyword())).intValue()).toArray(); return dropAndInsert(coll, objects); }
/** * @param coll * @param object * @return */ @Override public DBCollection apply(DBCollection coll, DBObject object) { List<DBObject> objects = coll.find().sort((DBObject) object.get(getKeyword())).toArray(); return dropAndInsert(coll, objects); }