DBComponent.cs 796 B

1234567891011121314151617181920212223242526272829303132333435
  1. using MongoDB.Driver;
  2. namespace Model
  3. {
  4. [ObjectSystem]
  5. public class DbComponentSystem : ObjectSystem<DBComponent>, IAwake
  6. {
  7. public void Awake()
  8. {
  9. this.Get().Awake();
  10. }
  11. }
  12. /// <summary>
  13. /// 连接mongodb
  14. /// </summary>
  15. public class DBComponent : Component
  16. {
  17. public MongoClient mongoClient;
  18. public IMongoDatabase database;
  19. public void Awake()
  20. {
  21. //DBConfig config = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.GetComponent<DBConfig>();
  22. //string connectionString = config.ConnectionString;
  23. //mongoClient = new MongoClient(connectionString);
  24. //this.database = this.mongoClient.GetDatabase(config.DBName);
  25. }
  26. public IMongoCollection<Component> GetCollection(string name)
  27. {
  28. return this.database.GetCollection<Component>(name);
  29. }
  30. }
  31. }