切片与投影与C# [英] Slice with Projection with C#
本文介绍了切片与投影与C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有什么方法使用c#驱动程序在一个查询中实现切片和投影?
下面是我想用c#实现的,但是我坚持,任何人都可以帮助我吗?
Is there any way to implement a slice along with a projection in just one query using the c# driver? Below is what i am trying to achieve using c#, but im stuck, can anyone help me out wit it?
db.employee.find({"employeeId": "999"}, { "empActivity" : { "$slice": -1 } }, {"employeeId": 1, "empActivity.transId": 1, _id: 0})
注意:empActivity是一个包含嵌套文档的数组,
Note : empActivity is a an array containing nested documents, my query above works perfectly via the mongo shell but i am not able to figure out its equivalent in C#.
推荐答案
有一种方法可以做到这一点与C#驱动程序。方法可以在构建器上进行,因此所有 .Slice()
和 .Include()
和 .Exclude()
There is a way to do this with the C# driver. Methods can be chanined on builders, so all of .Slice()
and .Include()
and .Exclude()
var fields = Fields.Slice("empActivity", -1)
.Include("employeeId", "empActivity.transId")
.Exclude("_id");
var cursor = collection.Find(query).SetFields(fields);
这篇关于切片与投影与C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文