优化mongodb模块并新增test示例

This commit is contained in:
orgin
2022-03-29 14:23:12 +08:00
parent 7d40a48a1b
commit ca48c443cd
2 changed files with 213 additions and 1 deletions

View File

@@ -81,10 +81,10 @@ func (s *Session) EnsureUniqueIndex(db string, collection string, indexKeys [][]
//keys[索引][每个索引key字段]
func (s *Session) ensureIndex(db string, collection string, indexKeys [][]string, bBackground bool, unique bool) error {
keysDoc := bsonx.Doc{}
var indexes []mongo.IndexModel
for _, keys := range indexKeys {
keysDoc := bsonx.Doc{}
for _, key := range keys {
keysDoc = keysDoc.Append(key, bsonx.Int32(1))
}
@@ -104,3 +104,7 @@ func (s *Session) ensureIndex(db string, collection string, indexKeys [][]string
func (s *Session) GetDefaultContext() (context.Context, context.CancelFunc) {
return context.WithTimeout(context.Background(), s.maxOperatorTimeOut)
}
func (s *Session) Collection(db string, collection string) *mongo.Collection {
return s.Database(db).Collection(collection)
}