Support primary key ID and unique key Name where api uses name

This commit is contained in:
breel
2020-08-02 09:59:47 -06:00
parent 37fe9415e7
commit 8e6e86955e
14 changed files with 68 additions and 49 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"local/dndex/config"
"local/dndex/storage/entity"
"log"
"time"
@@ -77,9 +78,9 @@ func (m Mongo) Insert(ctx context.Context, namespace string, apply interface{})
if err := bson.Unmarshal(b, &mapp); err != nil {
return err
}
if _, ok := mapp["_id"]; !ok {
if _, ok := mapp[entity.ID]; !ok {
return errors.New("no _id in new object")
} else if _, ok := mapp["_id"].(string); !ok {
} else if _, ok := mapp[entity.ID].(string); !ok {
return errors.New("non-string _id in new object")
}
c := m.client.Database(m.db).Collection(namespace)