Fix partialFilter in index
This commit is contained in:
@@ -2,7 +2,6 @@ package mongo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
"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)
|
collection := c.GetCollection(database, name)
|
||||||
|
|
||||||
log.Printf("%v", collection)
|
|
||||||
|
|
||||||
var filter bson.D
|
var filter bson.D
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ func (c *MongoClient) CreateIndexes(collection *mongo.Collection, cdef *Collecti
|
|||||||
|
|
||||||
for _, keyDef := range cdef.IndexSpecs {
|
for _, keyDef := range cdef.IndexSpecs {
|
||||||
log.Printf("Key Definition %s", keyDef["name"])
|
log.Printf("Key Definition %s", keyDef["name"])
|
||||||
|
|
||||||
kdb, err := bson.Marshal(keyDef)
|
kdb, err := bson.Marshal(keyDef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to marshal %v", err)
|
log.Printf("failed to marshal %v", err)
|
||||||
@@ -53,7 +54,7 @@ func (c *MongoClient) CreateIndexes(collection *mongo.Collection, cdef *Collecti
|
|||||||
|
|
||||||
nameVal := kdRaw.Lookup("name")
|
nameVal := kdRaw.Lookup("name")
|
||||||
if name, ok := nameVal.StringValueOK(); ok {
|
if name, ok := nameVal.StringValueOK(); ok {
|
||||||
opts = opts.SetName(name)
|
opts = opts.SetName(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
uniqueVal := kdRaw.Lookup("unique")
|
uniqueVal := kdRaw.Lookup("unique")
|
||||||
@@ -62,7 +63,12 @@ func (c *MongoClient) CreateIndexes(collection *mongo.Collection, cdef *Collecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
partialVal := kdRaw.Lookup("partialFilterExpression")
|
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)
|
opts = opts.SetPartialFilterExpression(partialFilterExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user