c# - MongoDB.NET中的Find()方法怎么返回指定的字段的值
高洛峰
高洛峰 2017-05-02 09:22:44
0
1
823

  使用的ASP.NET MVC5,想要从mongoDB中根据条件筛选然后读取指定的数据,类似关系型数据库中select fields1,fields form table where name='123'

  在.NET中操作mongoDB应该怎么写一个返回特定的字段的方法?看文档和搜索都找不到合适的解决放法,求助大家啦

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
我想大声告诉你

Although sometimes the documentation is incomplete, you should be able to find the answer to your question directly from the documentation, but you may not be looking in the right place.
Select the driver version:
https://api.mongodb.com/csharp/
The projection method is in the MongoCursor里面,而不是Findmethod

public virtual MongoCursor SetFields(
    params string[] fields
)

Like a series of other methods, it still returns MongoCursor, so you can actually do cascading operations on it, such as

collection.Find(...)
    .SetFields(...)
    .SetSortOrder(...)
    .SetSkip(...)
    .SetLimit(...)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template