in server/datasource/mongo/kv/kv_dao.go [330:360]
func (s *Dao) Exist(ctx context.Context, key, project, domain string, options ...datasource.FindOption) (bool, error) {
opts := datasource.FindOptions{}
for _, o := range options {
o(&opts)
}
if opts.LabelFormat != "" {
_, err := findKVByLabel(ctx, domain, opts.LabelFormat, key, project)
if err != nil {
if err == datasource.ErrKeyNotExists {
return false, nil
}
openlog.Error(err.Error())
return false, err
}
return true, nil
}
kvs, err := s.List(ctx, domain, project,
datasource.WithExactLabels(),
datasource.WithLabels(opts.Labels),
datasource.WithKey(key))
if err != nil {
openlog.Error("check kv exist: " + err.Error())
return false, err
}
if len(kvs.Data) != 1 {
return false, datasource.ErrTooMany
}
return true, nil
}