You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

  1. package mongodb
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filer2"
  5. "github.com/chrislusf/seaweedfs/weed/util"
  6. "go.mongodb.org/mongo-driver/mongo"
  7. "go.mongodb.org/mongo-driver/mongo/options"
  8. "time"
  9. )
  10. func init() {
  11. filer2.Stores = append(filer2.Stores, &MongodbStore{})
  12. }
  13. type MongodbStore struct {
  14. connect *mongo.Client
  15. }
  16. func (store *MongodbStore) GetName() string {
  17. return "mongodb"
  18. }
  19. func (store *MongodbStore) Initialize(configuration util.Configuration, prefix string) (err error) {
  20. return store.connection(configuration.GetString(prefix + "uri"))
  21. }
  22. func (store *MongodbStore) connection(uri string) (err error) {
  23. ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
  24. client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
  25. store.connect = client
  26. return err
  27. }
  28. func (store *MongodbStore) BeginTransaction(ctx context.Context) (context.Context, error) {
  29. return ctx, nil
  30. }
  31. func (store *MongodbStore) CommitTransaction(ctx context.Context) error {
  32. return nil
  33. }
  34. func (store *MongodbStore) RollbackTransaction(ctx context.Context) error {
  35. return nil
  36. }
  37. func (store *MongodbStore) InsertEntry(ctx context.Context, entry *filer2.Entry) (err error) {
  38. return nil
  39. }
  40. func (store *MongodbStore) UpdateEntry(ctx context.Context, entry *filer2.Entry) (err error) {
  41. return nil
  42. }
  43. func (store *MongodbStore) FindEntry(ctx context.Context, fullpath util.FullPath) (entry *filer2.Entry, err error) {
  44. return nil, nil
  45. }
  46. func (store *MongodbStore) DeleteEntry(ctx context.Context, fullpath util.FullPath) error {
  47. return nil
  48. }
  49. func (store *MongodbStore) DeleteFolderChildren(ctx context.Context, fullpath util.FullPath) error {
  50. return nil
  51. }
  52. func (store *MongodbStore) ListDirectoryEntries(ctx context.Context, fullpath util.FullPath, startFileName string, inclusive bool, limit int) (entries []*filer2.Entry, err error) {
  53. return nil, nil
  54. }
  55. func (store *MongodbStore) Shutdown() {
  56. ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
  57. store.connect.Disconnect(ctx)
  58. }