Skip to content

yuanyu90221/golang_with_mongo_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang_with_mongodb

golang with mongo

introduction

this is an exmple for golang to make connect to the mongodb

use the mongo db offical library mongo

initial

go mod init github.com/${your github account name}/${github repo name}
go get -u github.com/joho/godotenv
go get -u go.mongodb.org/mongo-driver/mongo
go get -u go.mongodb.org/mongo-driver/bson

connect setup

clientOptions := options.Client().ApplyURI(connectString)
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
    log.Fatal(err)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages