[JAVA-3893] Cannot use comparison operators with dates Created: 20/Nov/20  Updated: 27/Oct/23  Resolved: 20/Nov/20

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Elyes Gherib Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen 1.png     PNG File Screen 2.png    

 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!

 



 Comments   
Comment by Elyes Gherib [ 20/Nov/20 ]

Can you please delete this case? Problem solved.

Thanks

Generated at Thu Feb 08 09:00:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.