I have a project in spring boot and using mongoDb for database.
Now how do make this query work
db.mycoll.aggregate([{ $sample: { size: 1 } }])
How do I convert into custom query using @Query annotation in spring data mongodb?
I have a project in spring boot and using mongoDb for database.
Now how do make this query work
db.mycoll.aggregate([{ $sample: { size: 1 } }])
How do I convert into custom query using @Query annotation in spring data mongodb?
You can make a custom repo to achieve the same using mongoTemplate.
SampleOperation sample = Aggregation.sample(1);
Aggregation aggregation = newAggregation(sample);
AggregationResults<T> result =
this.mongoTemplate.aggregate(aggregation, "CollectionToSearch","Return-type-object");
return result.getMappedResults();