Skip to content

Commit 47f494a

Browse files
committed
docs: updated connection creation and usage
1 parent 82fcc1d commit 47f494a

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

docs/getting-started/creating-a-connection.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ sidebar_position: 2
44

55
# Creating a Connection
66

7-
All Connections in Elemental are managed by the `e_connection` package which can be imported as follows:
7+
All Connections in Elemental are managed by the `elemental` package which can be imported as follows:
88

99
```go
10-
import "github.com/elcengine/elemental/connection"
10+
import "github.com/elcengine/elemental/core"
1111
```
1212

1313
Connecting to a MongoDB database is a simple as calling the `ConnectURI` function with your connection string:
1414

1515
```go
16-
client := e_connection.ConnectURI("mongodb://localhost:27017")
16+
client := elemental.Connect("mongodb://localhost:27017")
1717
```
1818

1919
## Connecting with Custom Client Options
@@ -22,7 +22,7 @@ You can also pass custom client options from the `go.mongodb.org/mongo-driver/mo
2222

2323
```go
2424
opts := options.Client().SetTimeout(10 * time.Second)
25-
client := e_connection.Connect(e_connection.ConnectionOptions{
25+
client := elemental.Connect(elemental.ConnectionOptions{
2626
URI: "mongodb://localhost:27017",
2727
ClientOptions: opts,
2828
})
@@ -37,7 +37,7 @@ An alias is a human-readable name that you can assign to your connection. This i
3737
A connection without an alias is assigned the default alias **`default`**
3838

3939
```go
40-
client := e_connection.Connect(e_connection.ConnectionOptions{
40+
client := elemental.Connect(elemental.ConnectionOptions{
4141
Alias: "my-connection",
4242
URI: "mongodb://localhost:27017",
4343
})
@@ -46,45 +46,45 @@ client := e_connection.Connect(e_connection.ConnectionOptions{
4646
## Retrieve a Connection by Alias
4747

4848
```go
49-
client := e_connection.GetConnection("my-connection")
49+
client := elemental.GetConnection("my-connection")
5050
```
5151

5252
## Retrieve the default database in a Connection
5353

5454
- Returns the default database in the default connection
5555

5656
```go
57-
db := e_connection.UseDefault()
57+
db := elemental.UseDefaultDatabase()
5858
```
5959

6060
- Returns the default database in the connection with the alias "my-connection"
6161

6262
```go
63-
db := e_connection.UseDefault("my-connection")
63+
db := elemental.UseDefaultDatabase("my-connection")
6464
```
6565

6666
## Retrieve any database in a Connection
6767

6868
- Returns the database "my-database" in the default connection
6969

7070
```go
71-
db := e_connection.Use("my-database")
71+
db := elemental.UseDatabase("my-database")
7272
```
7373

7474
- Returns the database "my-database" in the connection with the alias "my-connection"
7575

7676
```go
77-
db := e_connection.Use("my-database", "my-connection")
77+
db := elemental.UseDatabase("my-database", "my-connection")
7878
```
7979

8080
## Disconnect from a Connection
8181

8282
```go
83-
e_connection.Disconnect()
83+
elemental.Disconnect()
8484
```
8585

8686
- Or disconnect from multiple connections
8787

8888
```go
89-
e_connection.Disconnect("default", "my-connection", "some-other-connection")
89+
elemental.Disconnect("default", "my-connection", "some-other-connection")
9090
```

docs/getting-started/listening-to-connection-events.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Elemental provides a way to listen to connection pool events such as `Connection
99
- Listens to the `ConnectionCreated` event of the default connection
1010

1111
```go
12-
e_connection.On("ConnectionCreated", func(alias string) {
12+
elemental.OnConnectionEvent("ConnectionCreated", func(alias string) {
1313
fmt.Println("Connection created for", alias)
1414
})
1515
```
1616

1717
- Listens to the `ConnectionCreated` event of a specific connection
1818

1919
```go
20-
e_connection.On("ConnectionCreated", func(alias string) {
20+
elemental.OnConnectionEvent("ConnectionCreated", func(alias string) {
2121
fmt.Println("Connection created for", alias)
2222
}, "my-connection")
2323
```
@@ -27,13 +27,13 @@ e_connection.On("ConnectionCreated", func(alias string) {
2727
- Unsubscribes from the `ConnectionCreated` event of the default connection
2828

2929
```go
30-
e_connection.Off("ConnectionCreated")
30+
elemental.RemoveConnectionEvent("ConnectionCreated")
3131
```
3232

3333
- Unsubscribes from the `ConnectionCreated` event of a specific connection
3434

3535
```go
36-
e_connection.Off("ConnectionCreated", "my-connection")
36+
elemental.RemoveConnectionEvent("ConnectionCreated", "my-connection")
3737
```
3838

3939
**For a full list of supported events, refer [this page](https://pkg.go.dev/go.mongodb.org/mongo-driver/event).**
@@ -48,7 +48,7 @@ poolMonitor := &event.PoolMonitor{
4848
fmt.Println("Pool event:", evt)
4949
},
5050
}
51-
client := e_connection.Connect(e_connection.ConnectionOptions{
51+
client := elemental.Connect(elemental.ConnectionOptions{
5252
URI: "mongodb://localhost:27017",
5353
PoolMonitor: poolMonitor,
5454
})

docs/indexing/creating-indexes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ indexModel := mongo.IndexModel{
3030
Keys: bson.D{{"Vitality", 1}},
3131
Options: options.Index().SetUnique(true),
3232
}
33-
e_connection.UseDefault().Collection("alghouls").Indexes().CreateOne(context.Background(), indexModel)
33+
elemental.UseDefaultDatabase().Collection("alghouls").Indexes().CreateOne(context.Background(), indexModel)
3434
```

0 commit comments

Comments
 (0)