我的用户POJO长这样:
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "User")
public class User {
@Id
private String id;
private String username;
private String password;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
我可以根据查询条件获取所有文档:
List<User> testBedsFromDB = mongoOperations.findAll(User.class);
我想跳过一些字段,比如密码
。我想获取所有文档中仅包含 id 和用户名的值
,密码可以为空或不包括在内
。我应该怎么做?