zoukankan      html  css  js  c++  java
  • c# Mongodb批量更新

    public void Put(List<OnlineItem> datas)
            {
                try
                {
                    string tblName = datas[0].beginTime.ToString("yyyy-MM-dd");
                    MongoCollection<BsonDocument> table = null;

                    if (tables.ContainsKey(tblName))
                    {
                        table = tables[tblName];
                    }
                    else
                    {
                        table = db.GetCollection(tblName);
                        tables.TryAdd(tblName, table);
                    }
                    var bulk = table.InitializeOrderedBulkOperation();
                    //var update = new UpdateBuilder();

                    foreach (var data in datas)
                    {
                        data.UpdateTime = DateTime.Now;
                        IMongoQuery query = Query.EQ("Seq", data.Seq);
                        var update = new UpdateDocument() { { "$set", BsonDocumentWrapper.Create(data) } };
                        bulk.Find(query).Update(update);
                    }
                    bulk.Execute();
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex, "Put");
                }
            }

  • 相关阅读:
    自学Python编程的第二天----------来自苦逼的转行人
    自学Python编程的第一天----------来自苦逼的转行人
    A-B 高精度
    A+B 高精度
    [NOI2002]银河英雄传说
    口袋的天空
    修复公路(并查集)
    并查集
    Surjectivity is stable under base change
    为什么Fourier分析?
  • 原文地址:https://www.cnblogs.com/94cool/p/6387414.html
Copyright © 2011-2022 走看看