mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化mongodb模块并新增test示例
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user