Sorting not worked properly when i sort with textScore and other field which are already indexed or the field which are runtime created.
i mentioned the query below :
[{"$match":{"$and":[{"$text":{"$search":"jeans"}}]}},{"$addFields":{"variantPrice":{"$let":{"vars":{"discountedVariants":{"$map":{"input":"$productVariants","as":"variant","in":{"$cond":{"if":{"$eq":["$$variant.discountPrice",null]},"then":"$$variant.price","else":"$$variant.discountPrice"}}}}},"in":{"$min":"$$discountedVariants"}}}}},{"$match":{"variantPrice":{"$gte":1,"$lte":100000}}},{"$sort":{"score":{"$meta":"textScore"},"createdAt":-1}},{"$skip":0},{"$limit":30}]
with above query i want the data like which is related to {“score”:{“$meta”:“textScore”} but for this data i want to sort with “createdAt” or any other field but it is not working.
i research so much but not found any solution.
Please give better solution