我有以下对象:
[BsonId]
public ObjectId Id { get; set; }
public string Area { get; set; }
public DateTime Date { get; set; }
public int MethodCalls { get; set; }
public Dictionary<string, ActionStats> Actions { get; set; }
ActionStats 对象如下所示:
public string Action { get; set; }
public int Count { get; set; }
public long TotalDuration { get; set; }
public Dictionary<int, int> Hourly { get; set; }
我希望能够像这样使用 FindAndModify 更新值:
Update<Statistic>.Inc(x => x.MethodCalls, 1).Inc(x => x.Actions[action.ToLower()].Count, 1);
但是,这在具有以下堆栈跟踪的第二个增量语句上失败:
堆栈跟踪——在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) 在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) 在 MongoDB.Driver.Linq.Utils .BsonSerializationInfoFinder.VisitGetItem(MethodCallExpression node) at MongoDB.Driver.Linq.ExpressionVisitor
1.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.VisitMember(MemberExpression node) at MongoDB.Driver.Linq.ExpressionVisitor
1.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder。 MongoDB.Driver.Linq.ExpressionVisitor1.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.GetSerializationInfo(Expression node, Dictionary
2 serializationInfoCache 的 Lambda(LambdaExpression 节点)) MongoDB.Driver.Builders.UpdateBuilder1.Inc(Expression
1 memberExpression,Int32 值)
如何更新子文档的字典值?