-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.go
45 lines (38 loc) · 842 Bytes
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
if err != nil {
fmt.Println(err)
return
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err = client.Connect(ctx)
if err != nil {
fmt.Println(err)
return
}
ogrenciCollection := client.Database("testdb").Collection("ogrenci")
updateResult, err := ogrenciCollection.UpdateOne(
context.TODO(),
bson.M{"no": 1200},
bson.D{
{"$set", bson.D{
{"isim", "Hasan"},
{"soyisim", "KILICI"},
{"sinif", "12/D"},
}},
},
)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%d satır düzenlendi\n", updateResult.ModifiedCount)
}