简体   繁体   English

查询仅返回某些字段?

[英]Query that returns only certain fields?

I've got a very large, structured document(s) stored in MongoDB, and am using Morphia to query and model it in Java. 我在MongoDB中存储了一个非常大的结构化文档,并且正在使用Morphia在Java中对其进行查询和建模。 I'd like to write a query that only returns a handful of the fields in that document, rather than returning the entire thing. 我想编写一个查询,该查询仅返回该文档中的少数几个字段,而不返回整个内容。 I've looked in the documentation on the Morphia site, but couldn't find anything that explains how to do this. 我已经查看了Morphia网站上的文档,但是找不到任何说明该操作的方法。 Is it possible to write a query like this with Morphia? 是否可以用Morphia编写这样的查询? In pseudocode it would be something like 用伪代码,它会像

GET doc.propertyA, doc.propertyB, doc.propertyX FROM doc WHERE doc.someOtherProperty = 'Foo'

Thoughts? 有什么想法吗? Or is Morphia not designed to operate in this manner? 还是Morphia并非设计为以这种方式运行? Is there something better I could try? 有什么我可以尝试的更好的方法吗?

example is better than words. 榜样胜于文字。

Query returns only "_id" field. 查询仅返回“ _id”字段。

datastore.createQuery(entityClazz.class).retrievedFields(true, Mapper.ID_KEY);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM