public static JSONObject listMessages(int id, int nb, int off,String last) throws emptyResultException {
		try {

			
			JSONObject json = new JSONObject();
			Mongo m = new Mongo(BDStatic.mongoDb_host,BDStatic.mongoDb_port);
			DB db = m.getDB(BDStatic.mysql_db);
			DBCollection collection = db.getCollection("messages");
			BasicDBObject query = new BasicDBObject();			
			
			if(id != -1)
				query.put("id",id);
			
			DBCursor cursor = collection.find(query).sort(new BasicDBObject("date",-1)).limit(nb).skip(off); 
			
			while(cursor.hasNext()){
				DBObject next = cursor.next();
				
				if(last != null && last != "" && next.get("_id").toString().equals(last))
				{
					cursor.close();
					m.close();
					return json;
				}
				
				json.accumulate("messages", next);
			}
			
			cursor.close();
			m.close();
			return json;
			
			}catch (UnknownHostException e) {
				return ErrorMsg.bdError();
			}catch (JSONException e) {
				return ErrorMsg.bdError();
			}
	}