title: MongoDB ISODate field search using Java
body: <p>I am having trouble searching ISODate field in mongodb using Java. I want to find exact matched date.</p>
  
  <p>Here's how I query first collection and get ISODate field "Timestamp". Once I get this date, I want to search another collection with the same "Timestamp" value.</p>
  
  <pre><code>    FindIterable&lt;Document&gt; docList = thermalComfortCollection.find();
      for(Document doc: docList) {
  
          String ts = doc.get("Timestamp").toString();
          System.out.println(ts);
  </code></pre>
  
  <p>...</p>
  
  <p>I am formatting ISODate since it returns me date in a different format that I would like to search. Therefore, I am converting it into this pattern "yyyy-MM-dd HH:mm:ss"</p>
  
  <pre><code>        final DateTimeFormatter inputFormat = 
                  DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy");
  
          // The parsed date
          final ZonedDateTime parsed = ZonedDateTime.parse(ts, inputFormat);
  
          // The output format
          final DateTimeFormatter outputFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
          String date = outputFormat.format(parsed);
  </code></pre>
  
  <p>I could not find how to write exact match statement for ISODate type, so I am putting both gte and lte conditions to get an exact match..!</p>
  
  <pre><code>        BasicDBObject query = new BasicDBObject("Timestamp", //
                            new BasicDBObject("$gte", date).append("$lte", date));
                  System.out.println(query);
  </code></pre>
  
  <p>And the query is not working. Could you give me any comment which part of my code is wrong?</p>