0

次のオブジェクトがあります。

[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);

ただし、これは 2 番目のインクリメント ステートメントで失敗し、次のスタック トレースが表示されます。

スタック トレース -- System.Number.StringToNumber(String str、NumberStyles オプション、NumberBuffer& number、NumberFormatInfo info、Boolean parseDecimal) at System.Number.ParseInt32(String s、NumberStyles style、NumberFormatInfo info) at MongoDB.Driver.Linq.Utils MongoDB.Driver.Linq.ExpressionVisitor の .BsonSerializationInfoFinder.VisitGetItem (MethodCallExpression ノード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) VisitLambda(LambdaExpression ノード) MongoDB.Driver.Linq.ExpressionVisitor 1.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit(Expression node) at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.GetSerializationInfo(Expression node, Dictionary2 serializationInfoCache) MongoDB.Driver.Builders.UpdateBuilder 1.Inc(Expression1 memberExpression, Int32 値)

サブドキュメントの辞書値を更新するにはどうすればよいですか?

4

1 に答える 1

2

MongoDB Official JIRA issue CSHARP-917が原因で動作が実装されているかどうかは疑問です。ただし、いつでも別の方法で行うことができます。

Update.Inc(string.Format("Actions.{0}.Count", action.ToLower()), 1);
于 2014-03-27T10:09:45.777 に答える