Beispiel #1
0
        public static void Main(string[] args)
        {
            var        list  = Get <sys_tables>();
            sys_tables table = list.Last();

            table.TableName = "测试表2";
            ReplaceOneResult result = Update(table.TableID, table);

            Console.ReadKey();
        }
Beispiel #2
0
        /// <summary>
        /// 更新文档
        /// </summary>
        /// <param name="tableId"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public static ReplaceOneResult Update(int tableId, sys_tables document)
        {
            IMongoDatabase db = client.GetDatabase(dbName);
            IMongoCollection <sys_tables> collection = db.GetCollection <sys_tables>("sys_tables");
            FilterDefinition <sys_tables> filter     = Builders <sys_tables> .Filter.Eq(x => x.TableID, tableId);

            //设置单个属性的新值
            // UpdateDefinition<Person> up = Builders<Person>.Update.Set(x => x.Sex, p.Sex);
            // 更新文档的单个属性
            // collection.UpdateOne(filter, up);

            //更新整个文档
            return(collection.ReplaceOne(filter, document));
        }