/// <summary> /// 修改机器人实体 /// </summary> /// <param name="robotEntity"></param> /// <returns></returns> public static bool UpdateRobotMasterEntity(Model.RobotEntity robotEntity) { try { string robotMasterCollectionName = Common.ConfigFileHandler.GetAppConfig("RobotMasterCollectionName"); var collection = MongodbHandler.GetInstance().GetCollection(robotMasterCollectionName); var filterID = Builders <BsonDocument> .Filter.Eq("_id", ObjectId.Parse(robotEntity.id)); BsonDocument update = robotEntity.ToBsonDocument(); //不能更新ID update.Remove("_id"); //更新 BsonDocument updateResult = collection.FindOneAndUpdate(filterID, update); if (updateResult != null) { return(true); } return(false); } catch (Exception ex) { throw ex; } }
/// <summary> /// 插入机器人 /// </summary> /// <param name="robotEntity"></param> /// <returns></returns> public static bool InsertRobotMasterEntity(Model.RobotEntity robotEntity) { try { string robotMasterCollectionName = Common.ConfigFileHandler.GetAppConfig("RobotMasterCollectionName"); var collection = MongodbHandler.GetInstance().mc_MongoDatabase.GetCollection <Model.RobotEntity>(robotMasterCollectionName); collection.InsertOne(robotEntity); return(true); } catch (Exception ex) { throw ex; } }