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

Cannot use comparison operators with dates

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Gone away
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      I'm trying to query documents with a date lesser than or equal to a given query date.

      Here's the query as written in a Spring Data repository (Java):

      { 
          'subscriptionPeriodStart': { $lte: ?0 }, 
          'nStickers': { $gt: 0 }, 
          'status': { $nin: [ 'Canceled', 'Refunded' ] } 
      }

      "?0" being the first parameter passed to the repository's method, of type java.util.Date.

       

      The query is translated by the driver into this query:

       

      db.bill.find({ 
       "subscriptionPeriodStart" : { "$lte" : 1608422400000},
       "nStickers" : { "$gt" : 0}, 
       "status" : { "$nin" : [ "Canceled", "Refunded" ] }
      })
      

       

      The result of the query is on screenshot "screen 2". No documents are returned.

      I rewrote the same query using another syntax:

      db.bill.find({ 
       "subscriptionPeriodStart" : { "$lte" : ISODate("2020-12-20T00:00:00.000Z")},
       "nStickers" : { "$gt" : 0}, 
       "status" : { "$nin" : [ "Canceled", "Refunded" ] } 
      })

      And the documents are returned (screenshot "screen 2").

       

      Is this a bug or a feature?

       

      Environment:

      • MongoDB: v3.6.17
      • Java driver: org.mongodb/mongo-java-driver v3.11.2
      • Spring Data: org.springframework.data/spring-data-mongodb v2.2.4.RELEASE
      • Java JDK v1.8.0_261

       

      Thanks!

       

      Attachments

        1. Screen 1.png
          Screen 1.png
          43 kB
        2. Screen 2.png
          Screen 2.png
          57 kB

        Activity

          People

            Unassigned Unassigned
            technical@tootsweet-app.com Elyes Gherib
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: