Search in sources :

Example 1 with MongoDb

use of fr.wseduc.mongodb.MongoDb in project statistics by OPEN-ENT-NG.

the class StatisticsController method deleteRegeneratedStatistics.

// delete all the statisticcs from mongoDB who will be generated again.
private void deleteRegeneratedStatistics(Date startDate, Date endDate, Handler<Either<String, JsonArray>> handler) {
    MongoDb mongo = MongoDb.getInstance();
    JsonObject criteria = new JsonObject();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd 00:00.00.000");
    String strStartDate = df.format(startDate);
    String strEndDate = df.format(endDate);
    // first condition
    final JsonArray cond = new JsonArray().addObject(new JsonObject().putObject("date", new JsonObject().putString("$gte", strStartDate)));
    // second condition
    cond.addObject(new JsonObject().putObject("date", new JsonObject().putString("$lt", strEndDate)));
    // query = condition1 AND condition2
    final JsonObject query = new JsonObject().putArray("$and", cond);
    // launch deletion
    mongo.delete("stats", query, MongoDbResult.validResultsHandler(handler));
}
Also used : JsonArray(org.vertx.java.core.json.JsonArray) JsonObject(org.vertx.java.core.json.JsonObject) MongoDb(fr.wseduc.mongodb.MongoDb) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

MongoDb (fr.wseduc.mongodb.MongoDb)1 SimpleDateFormat (java.text.SimpleDateFormat)1 JsonArray (org.vertx.java.core.json.JsonArray)1 JsonObject (org.vertx.java.core.json.JsonObject)1