Go语言支持哪些数据库?
package main import ( "context" "fmt" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) func main() { clientOptions := options.Client().ApplyURI("mongodb://localhost:27017") client, err := mongo.Connect(context.Background(), clientOptions) if err != nil { panic(err.Error()) } defer client.Disconnect(context.Background()) collection := client.Database("test").Collection("users") // 插入数据 _, err = collection.InsertOne(context.Background(), bson.D{ {"name", "Alice"}, {"age", 30}, }) if err != nil { panic(err.Error()) } // 查询数据 cursor, err := collection.Find(context.Background(), bson.D{}) if err != nil { panic(err.Error()) } defer cursor.Close(context.Background()) for cursor.Next(context.Background()) { var result bson.M err := cursor.Decode(&result) if err != nil { panic(err.Error()) } fmt.Println(result) } }
登录后复制
上一篇:如何选择支持Go语言的硬件设备?
-
基因剪辑技术的专利现状及原因解析2024-06-14
-
学会这几种技巧,你也能成为视频剪辑大师2024-07-04
-
学会剪辑视频的5个关键步骤2024-06-24
-
神仙级剪辑技术:这些软件你不能错过2024-06-29
-
深入了解PyCharm:快速删除项目的方法2024-05-16