Fix partialFilter in index
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user