spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

@Aggregation Invalid date format.

Open gabber3000 opened this issue 3 years ago • 2 comments

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.

gabber3000 avatar May 07 '22 21:05 gabber3000

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.

christophstrobl avatar May 09 '22 06:05 christophstrobl

thanks for the solution 💪

gabber3000 avatar May 09 '22 23:05 gabber3000