Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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
mongodb.NET驱动程序更新嵌套数组_.net_Mongodb_Mongodb .net Driver - Fatal编程技术网

mongodb.NET驱动程序更新嵌套数组

mongodb.NET驱动程序更新嵌套数组,.net,mongodb,mongodb-.net-driver,.net,Mongodb,Mongodb .net Driver,我试图增加通过索引访问的嵌套数组中的值。为了说明问题,客户机对象包含Order对象的列表。Order对象包含int星。我的目标是将Stars int增加一倍,如: await mongoContext.Clients.UpdateOneAsync(x => x.Id == model.PostId, Builders<Client>.Update.Inc(x => x.Orders.ElementAt(index).Stars

我试图增加通过索引访问的嵌套数组中的值。为了说明问题,客户机对象包含Order对象的列表。Order对象包含int星。我的目标是将Stars int增加一倍,如:

            await mongoContext.Clients.UpdateOneAsync(x => x.Id == model.PostId,
           Builders<Client>.Update.Inc(x => x.Orders.ElementAt(index).Stars, 1));
wait mongoContext.Clients.UpdateOneAsync(x=>x.Id==model.PostId,
Builders.Update.Inc(x=>x.Orders.ElementAt(index.Stars,1));
上面的代码给出了错误消息: 如果我传递的是一个精确的数字(不是变量),它可以正常工作:

            await mongoContext.Clients.UpdateOneAsync(x => x.Id == model.PostId,
           Builders<Client>.Update.Inc(x => x.Orders.ElementAt(0).Stars, 1));
wait mongoContext.Clients.UpdateOneAsync(x=>x.Id==model.PostId,
Builders.Update.Inc(x=>x.Orders.ElementAt(0.Stars,1));
我也尝试过更简单的方法
x=>x.Orders[index].Stars
(不是通过“ElementAt()”),但一直失败


欢迎任何帮助

这是一个已知问题,请检查


它在2.0.0以后的驱动程序版本中解决(2.6.0是当前版本)。

如何在代码中定义
索引
?它是作为参数通过控制器传递到的int变量。