private static void Main(string[] args) { new DB("test"); var doc = new Document(); doc.Save(); var subDoc = new SubDocument { Name = "iron man" }; Parallel.ForEach(Enumerable.Range(1, 20), _ => { var bulk = DB.Update <Document>(); bulk.Match(d => d.ID == doc.ID && !d.SubDocs.Any(s => s.Name == subDoc.Name)) .Modify(b => b.Push(d => d.SubDocs, subDoc)) .AddToQueue(); bulk.Match(d => d.ID == doc.ID && d.SubDocs.Any(s => s.Name == subDoc.Name)) .Modify(b => b.Inc(d => d.SubDocs[-1].Count, 1)) .AddToQueue(); bulk.Execute(); }); }
private static void Main(string[] args) { new DB("test"); var doc = new Document(); doc.Save(); var sub1 = new SubDocument { Name = "houston" }; var sub2 = new SubDocument { Name = "california" }; for (int i = 0; i <= 5; i++) { DB.Update<Document>() .Match(d => d.ID == doc.ID) .Modify(b => b.AddToSet(d => d.SubDocs, sub1)) .Execute(); DB.Update<Document>() .Match(d => d.ID == doc.ID) .Modify(b => b.AddToSet(d => d.SubDocs, sub2)) .Execute(); } Console.WriteLine($"sub document count is: {doc.SubDocCount()}"); // result is 2 Console.Read(); }