casbin/mongodb-adapter

Failing to migrate existing data to new version v3.0.0

arshadrk opened this issue · 4 comments

The existing index is not unique. But We try to create new index(which will create index if and only when there is no existing same index field) will throw an error as the unique option is conflicting between the existing one and the new one which we are trying to do now.

if _, err = collection.Indexes().CreateOne(
		context.Background(),
		mongo.IndexModel{
			Keys:    keysDoc,
			Options: options.Index().SetUnique(true),
		},
	); err != nil {
		return err
	}

Any How when adding a policy or role we will check if that already exist and will add only if that is not already available. This already preserves the uniqueness of it. Is this setunique a necessary one ? If that is not necessary, Shall I remove that and raise a pull request ?

@arshadrk I suggest add a new method like: NewAdapterWithModelOptions(opt), opt instead of options.Index().SetUnique(true) of default. What do you think?

Closed as stale.