我在MongoDB上使用Spring Boot。我必须从一个包含另一个集合作为数据一部分的集合中获取数据。
我的收藏的结构就像
DC收藏
Dc={
field A,
Field B,
CC collection={
---its fields----
---it also contains one Collection-----
}
}
我必须应用查询,就像我应该从DC获取选定数据,而从CC收集仅获取两个字段一样。 我在类似的存储库中使用查询,
@Query("{ 'dealCodeId':1, 'dealCode':1,'startDate':1,'endDate':1 ,'isActive':1,'createdOn':0,'clientId':1,'clientName':1,'costCenter.costCenterId':1,'costCenter.costCenterName':1}}")
List<DealCode> findAllByIsActiveTrue();
还导入了
import org.springframework.data.jpa.repository.Query;
我的交易代码集合就像
{
"_id" : ObjectId("5b44b3797b33b01bb81dc440"),
"_class" : "com.exelatech.printshop.model.DealCode",
"dealCode" : "EFGHI ",
"startDate" : ISODate("2018-07-15T18:30:00.000Z"),
"endDate" : ISODate("2018-07-23T18:30:00.000Z"),
"status" : "",
"ISACTIVE" : true,
"CREATEDON" : ISODate("2018-07-10T13:24:09.011Z"),
"CLIENTID" : "5ae02e694b881c47441d61f0",
"ClientName" : "ClientAN",
"costCenter" : {
"$ref" : "costcenter",
"$id" : ObjectId("5af29f264e69034e00e720f3")
}
}
我的成本中心选择就像
{
"_id" : ObjectId("5b2b5753354bba249084f763"),
"_class" : "com.exelatech.printshop.model.CostCenter",
"costcentercode" : "2345",
"costcentername" : "cos2345",
"budgetlimit" : 1312423425.0,
"active" : true,
"createdon" : ISODate("2018-06-21T07:44:19.357Z"),
"clientid" : "5add73662b7a5c51889fc040",
"clientName" : "NewClient",
"client" : {
"clientId" : "5add73662b7a5c51889fc040",
"clientName" : "NewClient"
},
"groups" : [
{
"$ref" : "group",
"$id" : ObjectId("5af1a05f354bba2540dac3fc")
}
]
}
How should I query?