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