"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/readpref"
database := client.Datbase("haha")
database.CreateCollection(context.TODO(),“hehe”")
mod2 := mongo.IndexModel{ Keys: bson.D { {"name",1},{"age",1}, }, Options: nil, } s, err := coll.Indexes().CreateOne(context.TODO(),mod2) if err != nil { fmt.Println("Indexes().CreateOne() ERROR:", err) } else { fmt.Println("CreateOne() index:", s) // 索引名字name_1_age_1 fmt.Println("CreateOne() type:", reflect.TypeOf(ind), "\n")// 类型 string }