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:
Mazyar
2026-06-06 21:36:43 +03:30
parent 5af3bfaa1a
commit c91b525e7e
5 changed files with 164 additions and 28 deletions
+12 -1
View File
@@ -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)