diff --git a/generic.go b/generic.go index 53a1627..c1c01c0 100644 --- a/generic.go +++ b/generic.go @@ -2,7 +2,6 @@ package mongo import ( "errors" - "log" "context" "go.mongodb.org/mongo-driver/v2/bson" @@ -26,8 +25,6 @@ func (c *MongoClient) GenericFind(ctx context.Context, payload *FindRequest) (*D collection := c.GetCollection(database, name) - log.Printf("%v", collection) - var filter bson.D var err error diff --git a/main_index.go b/main_index.go index e24ac07..ded84c3 100644 --- a/main_index.go +++ b/main_index.go @@ -22,6 +22,7 @@ func (c *MongoClient) CreateIndexes(collection *mongo.Collection, cdef *Collecti for _, keyDef := range cdef.IndexSpecs { log.Printf("Key Definition %s", keyDef["name"]) + kdb, err := bson.Marshal(keyDef) if err != nil { log.Printf("failed to marshal %v", err) @@ -53,7 +54,7 @@ func (c *MongoClient) CreateIndexes(collection *mongo.Collection, cdef *Collecti nameVal := kdRaw.Lookup("name") if name, ok := nameVal.StringValueOK(); ok { - opts = opts.SetName(name) + opts = opts.SetName(name) } uniqueVal := kdRaw.Lookup("unique") @@ -62,7 +63,12 @@ func (c *MongoClient) CreateIndexes(collection *mongo.Collection, cdef *Collecti } partialVal := kdRaw.Lookup("partialFilterExpression") - if partialFilterExpression, ok := partialVal.BooleanOK(); ok { + if partialVal.Type == bson.TypeEmbeddedDocument { + var partialFilterExpression bson.M + if err := bson.Unmarshal(partialVal.Value, &partialFilterExpression); err != nil { + log.Printf("failed to unmarshal partial filter: %v", err) + } + opts = opts.SetPartialFilterExpression(partialFilterExpression) }