Cannot use comparison operators with dates

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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!

       

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

            Assignee:
            Unassigned
            Reporter:
            Elyes Gherib
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: