vanishcode / Blog

vanishcodeのblog
https://vanishcode.com
6 stars 0 forks source link

mongo-go-driver使用 #78

Open vanishcode opened 5 years ago

vanishcode commented 5 years ago

其实自己crtl+f搜索就可以,链接:

https://github.com/mongodb/mongo-go-driver/blob/master/examples/documentation_examples/examples.go

不过不知什么原因,官方的示例

ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, err := mongo.Connect(ctx, "mongodb://localhost:27017")

我总是失败,后来我试了一下这种

client, err := mongo.Connect(context.Background(), "mongodb://localhost:27017", nil)

就好使了 推测可能是context这里出了什么问题或者自己没用对。。。。。。