[英]Spring Data Mongo Query Field parameters
I'm playing with Spring Data Mongo Query and wondering about the field property parameters. 我正在使用Spring Data Mongo Query,想知道字段属性参数。 Here is the example that I got from the documentation :
这是我从文档中获得的示例:
public interface PersonRepository extends MongoRepository<Person, String>
@Query(value="{ 'firstname' : ?0 }", fields="{ 'firstname' : 1, 'lastname' : 1}")
List<Person> findByThePersonsFirstname(String firstname);
}
The question is: What is the meaning of 1
in { 'firstname' : 1, 'lastname' : 1}
? 问题是:
{ 'firstname' : 1, 'lastname' : 1}
的1
是什么意思?
1 means that both 'firstname' and 'lastname' will be included in the resulted document. 1表示“名字”和“姓氏”都将包含在结果文档中。 For example, if you have 'salary' field you can exclude it from result by typing
'salary': 0
. 例如,如果您有'salary'字段,则可以通过键入
'salary': 0
将其从结果中排除。
You can use MongoTemplate
for querying.First you declare query
and after that you can declare criteria
.Below is an example : 您可以使用
MongoTemplate
进行查询。首先声明query
,然后声明criteria
下面是一个示例:
Criteria criteria = Criteria.where("kademeler.isemriId").is(isemriNo)
.and("ogag").is(1);
Query query = new Query(criteria);
query.fields().exclude("salary"); //for excluding a field, this is "salary" for you
List<AboneAriza> result = mongoTemplate.find(query, AboneAriza.class);
只是要添加,默认情况下也会返回文档的ID,因此,这将意味着返回名字,姓氏以及文档的_id,并且由于已经回答将字段设置为零,因此不会返回该ID。返回文档时的特定字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.