func DatabaseConnect() (db *mongo.Database, err error) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
if err != nil {
return
}
db = client.Database("students")
return
}
this above function connects to a database which is already present on mongoDB server. But can we write a function silimar to this one, which will create/drop a database and some collections also.
func HandleDatabases(){
// for deleting / creating / managing mongoDB databases and collections ?
}