diff --git a/pkg/common/db/mgo/black.go b/pkg/common/db/mgo/black.go index 52abcda81..338a74e54 100644 --- a/pkg/common/db/mgo/black.go +++ b/pkg/common/db/mgo/black.go @@ -13,7 +13,10 @@ import ( func NewBlackMongo(db *mongo.Database) (relation.BlackModelInterface, error) { coll := db.Collection("black") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"owner_user_id": 1, "block_user_id": 1}, + Keys: bson.D{ + {Key: "owner_user_id", Value: 1}, + {Key: "block_user_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/conversation.go b/pkg/common/db/mgo/conversation.go index 7f2107e59..31bb896c8 100644 --- a/pkg/common/db/mgo/conversation.go +++ b/pkg/common/db/mgo/conversation.go @@ -15,7 +15,10 @@ import ( func NewConversationMongo(db *mongo.Database) (*ConversationMgo, error) { coll := db.Collection("conversation") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"owner_user_id": 1, "conversation_id": 1}, + Keys: bson.D{ + {Key: "owner_user_id", Value: 1}, + {Key: "conversation_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/friend.go b/pkg/common/db/mgo/friend.go index 40c2cbc45..2b64e6c59 100644 --- a/pkg/common/db/mgo/friend.go +++ b/pkg/common/db/mgo/friend.go @@ -20,7 +20,10 @@ type FriendMgo struct { func NewFriendMongo(db *mongo.Database) (relation.FriendModelInterface, error) { coll := db.Collection("friend") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"owner_user_id": 1, "friend_user_id": 1}, + Keys: bson.D{ + {Key: "owner_user_id", Value: 1}, + {Key: "friend_user_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/friend_request.go b/pkg/common/db/mgo/friend_request.go index 5886258d4..f3115e6cf 100644 --- a/pkg/common/db/mgo/friend_request.go +++ b/pkg/common/db/mgo/friend_request.go @@ -14,7 +14,10 @@ import ( func NewFriendRequestMongo(db *mongo.Database) (relation.FriendRequestModelInterface, error) { coll := db.Collection("friend_request") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"from_user_id": 1, "to_user_id": 1}, + Keys: bson.D{ + {Key: "from_user_id", Value: 1}, + {Key: "to_user_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/group.go b/pkg/common/db/mgo/group.go index 88b9a0f21..aa03a58e6 100644 --- a/pkg/common/db/mgo/group.go +++ b/pkg/common/db/mgo/group.go @@ -14,7 +14,9 @@ import ( func NewGroupMongo(db *mongo.Database) (relation.GroupModelInterface, error) { coll := db.Collection("group") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"group_id": 1}, + Keys: bson.D{ + {Key: "group_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/group_member.go b/pkg/common/db/mgo/group_member.go index 34069b7f3..bf4d7e2d4 100644 --- a/pkg/common/db/mgo/group_member.go +++ b/pkg/common/db/mgo/group_member.go @@ -14,7 +14,10 @@ import ( func NewGroupMember(db *mongo.Database) (relation.GroupMemberModelInterface, error) { coll := db.Collection("group_member") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"group_id": 1, "user_id": 1}, + Keys: bson.D{ + {Key: "group_id", Value: 1}, + {Key: "user_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/group_request.go b/pkg/common/db/mgo/group_request.go index d48ec8906..5b8c9cf7d 100644 --- a/pkg/common/db/mgo/group_request.go +++ b/pkg/common/db/mgo/group_request.go @@ -13,7 +13,10 @@ import ( func NewGroupRequestMgo(db *mongo.Database) (relation.GroupRequestModelInterface, error) { coll := db.Collection("group_request") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"group_id": 1, "user_id": 1}, + Keys: bson.D{ + {Key: "group_id", Value: 1}, + {Key: "user_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/log.go b/pkg/common/db/mgo/log.go index 9dcf703a9..acbb6dd79 100644 --- a/pkg/common/db/mgo/log.go +++ b/pkg/common/db/mgo/log.go @@ -15,14 +15,20 @@ func NewLogMongo(db *mongo.Database) (relation.LogInterface, error) { coll := db.Collection("log") _, err := coll.Indexes().CreateMany(context.Background(), []mongo.IndexModel{ { - Keys: bson.M{"log_id": 1}, + Keys: bson.D{ + {Key: "log_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }, { - Keys: bson.M{"user_id": 1}, + Keys: bson.D{ + {Key: "user_id", Value: 1}, + }, }, { - Keys: bson.M{"create_time": -1}, + Keys: bson.D{ + {Key: "create_time", Value: -1}, + }, }, }) if err != nil { diff --git a/pkg/common/db/mgo/object.go b/pkg/common/db/mgo/object.go index 0a6e1031c..e618aa24b 100644 --- a/pkg/common/db/mgo/object.go +++ b/pkg/common/db/mgo/object.go @@ -12,7 +12,9 @@ import ( func NewS3Mongo(db *mongo.Database) (relation.ObjectInfoModelInterface, error) { coll := db.Collection("s3") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"name": 1}, + Keys: bson.D{ + {Key: "name", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil { diff --git a/pkg/common/db/mgo/user.go b/pkg/common/db/mgo/user.go index a9e661c31..a87ec394d 100644 --- a/pkg/common/db/mgo/user.go +++ b/pkg/common/db/mgo/user.go @@ -14,7 +14,9 @@ import ( func NewUserMongo(db *mongo.Database) (relation.UserModelInterface, error) { coll := db.Collection("user") _, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{ - Keys: bson.M{"user_id": 1}, + Keys: bson.D{ + {Key: "user_id", Value: 1}, + }, Options: options.Index().SetUnique(true), }) if err != nil {