Refactor MongoDB index creation to use NonEmptyStringPartialFilter for improved clarity and consistency. Update GetOJS function to utilize context and user agent for HTTP requests, enhancing error handling and response management.
This commit is contained in:
+12
-1
@@ -17,7 +17,7 @@ func NewIndex(name string, keys bson.D) *Index {
|
||||
return &Index{
|
||||
Name: name,
|
||||
Keys: keys,
|
||||
Options: options.Index(),
|
||||
Options: options.Index().SetName(name),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,17 @@ func (i *Index) WithExpireAfterSeconds(seconds int32) *Index {
|
||||
return i
|
||||
}
|
||||
|
||||
// NonEmptyStringPartialFilter returns a partial-index filter for non-empty string field values.
|
||||
// MongoDB partial indexes do not support $ne; use $gt "" instead.
|
||||
func NonEmptyStringPartialFilter(field string) bson.M {
|
||||
return bson.M{
|
||||
field: bson.M{
|
||||
"$type": "string",
|
||||
"$gt": "",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// WithPartialFilterExpression sets the partial filter expression for the index
|
||||
func (i *Index) WithPartialFilterExpression(filter bson.M) *Index {
|
||||
i.Options.SetPartialFilterExpression(filter)
|
||||
|
||||
Reference in New Issue
Block a user