For import, create ID if absent
parent
acb3c93ead
commit
702720326b
|
|
@ -7,6 +7,7 @@ import (
|
|||
"local/dndex/storage/operator"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
)
|
||||
|
||||
|
|
@ -49,6 +50,9 @@ func (rest *REST) dumpIn(w http.ResponseWriter, r *http.Request) {
|
|||
for namespace, ones := range request {
|
||||
if namespace == scope.Namespace {
|
||||
for _, one := range ones {
|
||||
if one.ID == "" {
|
||||
one.ID = uuid.New().String()
|
||||
}
|
||||
if err := rest.g.Insert(r.Context(), scope.Namespace, one); err != nil {
|
||||
if err := rest.g.Update(r.Context(), scope.Namespace, bson.M{entity.ID: one.ID}, operator.SetMany{Value: one}); err != nil {
|
||||
rest.respError(w, err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue