Support primary key ID and unique key Name where api uses name
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user