我必须使用针对以下代码的spring数据存储库查询获取Mongo数据库中数组(嵌入文档)的最后一项, 即,对于下面的文档,我必须使用@Query找到客户的最后一个产品,你能帮忙吗?
Spring数据库类:
public interface CustomerRepository extends MongoRepository<Customer, String> {
@Query(??????)
Product findLastProduct(String name);
}
Mongo数据库中的文档:
{
"_id" : ObjectId("5799d381e8d3966825444dc3"),
"_class" : "com.xyz.models.Customer",
"name" : "Sara",
"createdBy" : "John",
"createdDateTime" : ISODate("2016-07-28T09:42:25.055Z"),
"products" : [ { "name" : "product1", "deliveryPriority" : "LOW" }, { "name" : "product2", "deliveryPriority" : "MEDIUM" } ]
}