使用projections查询collection中指定属性
Query query=new Query();
Criteria criteria=new Criteria();
criteria.and("accountId").is(accountId);
query.addCriteria(criteria);
query.fields().include("templateId").include("templateName").include("templateDesc");//查询指定属性
List<FormTemplate> formTemplates = mongoTemplate.find(query, FormTemplate.class);
转义成查询json
{ "accountId" : { "$numberLong" : "2" } } fields: Document{{templateName=1, templateDesc=1, _id=1}}