Spring Data Mongo 查询字段参数 [英] Spring Data Mongo Query Field parameters

查看:32
本文介绍了Spring Data Mongo 查询字段参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring Data Mongo Query 并想知道字段属性参数.这是我从 文档:

I'm playing with Spring Data Mongo Query and wondering about the field property parameters. 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);
}

问题是:{ 'firstname' : 1, 'lastname' : 1}中的1是什么意思?

The question is: What is the meaning of 1 in { 'firstname' : 1, 'lastname' : 1}?

推荐答案

1 表示 'firstname' 和 'lastname' 都将包含在结果文档中.例如,如果您有 'salary' 字段,您可以通过键入 'salary': 0 将其从结果中排除.

1 means that both 'firstname' and 'lastname' will be included in the resulted document. For example, if you have 'salary' field you can exclude it from result by typing 'salary': 0.

这篇关于Spring Data Mongo 查询字段参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆