Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-624

Date range with mongoTemplate gte and lte function is not working on cloudfoundry.

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Hi! I've inserted data to cloudfoundry(cf) mongodb with the following script.

      Expense expense162 = new Expense();
      expense162.setExpenseDate(simpleDateFormat.parse("2012-08-01 00:00:00.0"));
      mongoTemplate.insert(expense162, "expense");
       
      Expense expense163 = new Expense();
      expense163.setExpenseDate(simpleDateFormat.parse("2012-08-04 00:00:00.0"));
      mongoTemplate.insert(expense163, "expense");
       
      Expense expense164 = new Expense();
      expense164.setExpenseDate(simpleDateFormat.parse("2012-08-04 00:00:00.0"));
      mongoTemplate.insert(expense164, "expense");
       
      Expense expense165 = new Expense();
      expense165.setExpenseDate(simpleDateFormat.parse("2012-08-04 00:00:00.0"));
      mongoTemplate.insert(expense165, "expense");
       
      Expense expense166 = new Expense();
      expense166.setExpenseDate(simpleDateFormat.parse("2012-08-01 00:00:00.0"));
      mongoTemplate.insert(expense166, "expense");
       
      Expense expense167 = new Expense();
      expense167.setExpenseDate(simpleDateFormat.parse("2012-08-03 00:00:00.0"));
      mongoTemplate.insert(expense167, "expense");

      Now I'm trying fetching the code with the following java code.

      String[] arrMOnthYr = interval.split("-");
      Calendar calendar1 = new GregorianCalendar(Integer.parseInt(arrMOnthYr[1]), Integer.parseInt(arrMOnthYr[0])-1, Calendar.DATE);
      calendar1.set(Calendar.DATE, calendar1.getActualMinimum(Calendar.DATE));
       
      Calendar calendar2 = new GregorianCalendar(Integer.parseInt(arrMOnthYr[1]), Integer.parseInt(arrMOnthYr[0])-1, Calendar.DATE);
      calendar2.set(Calendar.DATE, calendar2.getActualMaximum(Calendar.DATE));
      List<Expense> list = expenseService.getAllExpense(request.getSession()
      .getAttribute("userid").toString(), calendar1.getTime(),
      calendar2.getTime());
       
      ---------------service layer code-----------
       
      public List<Expense> getAllExpense(String uid, Date begin, Date end) {
       
      System.out.println("Begin---> "+begin);
      System.out.println("End---> "+end);
       
      Criteria c = new Criteria().andOperator(Criteria.where("expenseDate")
      .gte(begin), Criteria.where("expenseDate").lte(end));
      c = c.and("userid").is(uid);
       
      Query query = new Query(c);
      List<Expense> l = mongoTemplate.find(query, Expense.class);
      System.out.println("The size of mb is "+l.size());
      return l;
      }

      while I try this on my local mongodb and tomcat server it says.

      Begin---> Wed Aug 01 00:00:00 IST 2012
      End---> Fri Aug 31 00:00:00 IST 2012
      2012-08-16 00:04:11,540{HH:mm:ss} DEBUG [tomcat-http--24] (MongoTemplate.java:1257) - find using query: { "$and" : [ { "expenseDate" : { "$gte" :

      { "$date" : "2012-07-31T18:30:00.000Z"}

      }} , { "expenseDate" : { "$lte" :

      { "$date" : "2012-08-30T18:30:00.000Z"}

      }}] , "userid" : "5d88cd6f-6f6f-4957-abc2-24f5e2c853ee"} fields: null for class: class com.expense.domains.Expense in collection: expense
      The size of mb is 6

      But while I try to run the same code on cloudfoundry it prints

      Begin---> Wed Aug 01 00:00:00 UTC 2012
      End---> Fri Aug 31 00:00:00 UTC 2012
      2012-08-15 18:32:44,707{HH:mm:ss} DEBUG [http-11297-1] (MongoTemplate.java:1257) - find using query: { "$and" : [ { "expenseDate" : { "$gte" :

      { "$date" : "2012-08-01T00:00:00.000Z"}

      }} , { "expenseDate" : { "$lte" :

      { "$date" : "2012-08-31T00:00:00.000Z"}

      }}] , "userid" : "5d88cd6f-6f6f-4957-abc2-24f5e2c853ee"} fields: null for class: class com.expense.domains.Expense in collection: expense
      The size of mb is 0

      There might be a timezone problem... I don't know.

      I've crossed verified that cloudfoundry mongodb and my local mongodb contains the exactly same data.

      While I say findAll() for expense on cloudfoundry it returns 6 records, But while I give the same for daterange with gte and lte function the same is not returning any record on cloudfoundry.

      Please suggest me solution ASAP since I'm stuck because of this issue.

      Thanks

      Jitender Saini

      Attachments

        Activity

          People

            Unassigned Unassigned
            saini.jitender@gmail.com Jitender Saini
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: