/// <summary> /// 添加 /// </summary> /// <param name="model">FriendsModel</param> /// <returns>true or false</returns> public bool Add(StepRankingModel model) { MongoClient client = new MongoClient(connection); var db = client.GetDatabase(this.dbName); var collection = db.GetCollection <StepRankingModel>(this.collection); object obj = ObjectIdGenerator.Instance.GenerateId(collection, model); model.Id = obj.ToString(); //model.Id = Guid.NewGuid().ToString("N"); //新增,则将第一次上传的步数赋值给总步数,后天更新是每次递增,下面一个方法中处理(UpdateModel) model.Total = model.Day; collection.InsertOneAsync(model); return(true); }
/// <summary> /// 更新 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateModel(StepRankingModel model, int curTotal) { MongoClient client = new MongoClient(connection); var db = client.GetDatabase(this.dbName); var collection = db.GetCollection <StepRankingModel>(this.collection); //过滤条件 var filter = Builders <StepRankingModel> .Filter.Where(x => x.ChildId == model.ChildId); //更新内容 var update = Builders <StepRankingModel> .Update .Set("Day", model.Day) .Set("Date", model.Date) .Set("UpdateTime", model.UpdateTime) .Set("Total", curTotal); collection.UpdateOneAsync(filter, update); return(true); }