MongoDB LinQ“选择"方法真的将只检索字段的子集吗? [英] MongoDB LinQ "Select" method will really retrieve only a subset of fields?

查看:63
本文介绍了MongoDB LinQ“选择"方法真的将只检索字段的子集吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#官方驱动程序(但使用LinQ作为基本体系结构)在Internet上搜索如何在MongoDB中检索字段的子集,我发现如何在MongoDB Shell中做到这一点.

Searching across the internet how to retrieve a subset of fields in MongoDB, using C# official driver (but using LinQ as the base architecture) I found how to do this in MongoDB shell.

// selecting only "field" of a collection
db.collection.find( { field : 'value' }, { field: 1 } ); 

然后,我在C#LinQ教程中找到了Select方法,它等效于此方法:

Then, I found at C# LinQ Tutorial the Select method, which is equivalent to this:

collection.AsQueryable<T>().Select(x => new { x.field });

但是,该教程说方法"用于从匹配的文档中投影新的结果类型".

However, the tutorial says the method "is used to project a new result type from the matching documents".

如何确保此方法仅检索字段子集而不检索整个结果,然后仅将子集选择到新对象中?

How to ensure this method will retrieve only the subset of fields and not the entire result and then select only the subset into a new object?

驱动程序将在检索结果之前构建查询命令吗?

推荐答案

驱动程序当前未检索字段的子集.如果需要该功能,则需要手动进行.此功能的票证在这里: https://jira.mongodb.org/browse/CSHARP-456 .如有需要,请随时留下反馈或投票.

The driver does not currently retrieve a subset of the fields. If you need that functionality, you'll need to do it manually. The ticket for this functionality is here: https://jira.mongodb.org/browse/CSHARP-456. Feel free to leave feedback or vote it up if you need this.

这篇关于MongoDB LinQ“选择"方法真的将只检索字段的子集吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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