Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么Inc()和PullFilter()不能一起工作?_C#_.net_Mongodb_Mongodb Query - Fatal编程技术网

C# 为什么Inc()和PullFilter()不能一起工作?

C# 为什么Inc()和PullFilter()不能一起工作?,c#,.net,mongodb,mongodb-query,C#,.net,Mongodb,Mongodb Query,为什么这个Inc()和PullFilter()不能正确更新我的文档(只有Inc()函数可以工作并更新文档中的my Count属性) \u rooms.UpdateOne( Builders.Filter.Where(x=>x.RoomId==RoomId), 建设者。更新 .PullFilter(x=>x.Players,y=>y.UserId==UserId) .Inc(“PlayerCount”,-1)); 公开课选手 { 公共字符串用户标识{get;set;} } 公共部分教室 { 公共字

为什么这个Inc()和PullFilter()不能正确更新我的文档(只有Inc()函数可以工作并更新文档中的my Count属性)

\u rooms.UpdateOne(
Builders.Filter.Where(x=>x.RoomId==RoomId),
建设者。更新
.PullFilter(x=>x.Players,y=>y.UserId==UserId)
.Inc(“PlayerCount”,-1));
公开课选手
{
公共字符串用户标识{get;set;}
}
公共部分教室
{
公共字符串RoomId{get;set;}
}

结果是数组元素(x.Property)没有按照mu PullFilter()的指定移除。它可以与push一起使用,但不确定为什么不能与pullfilter一起使用。

能否显示
类的定义?您确定数组元素的id也等于文档的id吗?当使用Push()而不是PullFilter将项添加到数组中时,完全相同的方法是有效的。PullFilter()单独工作很好,不包括Inc()子句。您能显示
类的定义吗?你确定数组元素也有一个与文档id相等的id吗?类有一个名为Count的int属性,列表也有一个id。我传递给函数的id也存在于Players i'd属性中。并且你要删除的
播放器
文档具有相同的id?
_rooms.UpdateOne(
Builders<Room>.Filter.Where(x => x.RoomId == roomId),
Builders<Room>.Update
.PullFilter(x => x.Players, y => y.UserId == userId)
.Inc("PlayerCount", -1));

public class Player
{
public string UserId { get; set; }
}

public partial class Room
{
public string RoomId { get; set; }
}