DBComponent学习笔记
请大家关注我的微博:@NormanLin_BadPixel坏像素
public MongoClient mongoClient;
public IMongoDatabase database;
public void Awake()
{
DBConfig config = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.GetComponent<DBConfig>();
string connectionString = config.ConnectionString;
mongoClient = new MongoClient(connectionString);
this.database = this.mongoClient.GetDatabase(config.DBName);
}
public IMongoCollection<Component> GetCollection(string name)
{
return this.database.GetCollection<Component>(name);
}
这个组件储存了MongoDB的相关连接信息。需要注意的是MongoDB的地址从StartConfigComponent.StartConfig中再获取的,而不是从StartConfigComponent.DBConfig。我的理解是,不同的服务也对应不同的数据库。
其他的,应该是MongoDB于C# 的用法。