spring-data-mongodb
spring-data-mongodb copied to clipboard
@Aggregation Invalid date format.
I have this simple aggregation:
public static final String match_finById = "{$match: {_id: ObjectId(?0)}}";
public static final String match_findById_date = "{$match: {'dynamicFields.validationDate': {$lte: ISODate('?1')}}}";
@Aggregation(pipeline = {match_finById,match_findById_date})
List<CompanyModelFull> findCompanyById(String id,Date date);
any date passed as parameter ('? 0) I get this error
org.bson.json.JsonParseException: Invalid date format.
at org.springframework.data.mongodb.util.json.ParameterBindingJsonReader.visitISODateTimeConstructor(ParameterBindingJsonReader.java:1082)
at org.springframework.data.mongodb.util.json.ParameterBindingJsonReader.readBsonType(ParameterBindingJsonReader.java:274)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.decode(ParameterBindingDocumentCodec.java:227)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.decode(ParameterBindingDocumentCodec.java:66)
at org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec.readValue(ParameterBindingDocumentCodec.java:360)
is it a bug? can someone kindly show me an example? thank you.
Thanks for bringing this up! The parameter binding only considers extended JSON $date as in { $lte : { $date : '?1' } } and not the ISODate keyword. Since the parameter already is a Date, { $lte : ?1 } might also do.
thanks for the solution 💪