insert and load channel

This commit is contained in:
lyx0 2021-10-25 23:46:27 +02:00
parent 203f921c18
commit 5279e772d1

View file

@ -35,4 +35,46 @@ func Connect() {
} }
fmt.Println(databases) fmt.Println(databases)
// Interact with data
type Channel struct {
Name string `bson:"name,omitempty"`
}
/*
Get my collection instance
*/
collection := client.Database("nourybot").Collection("channels")
/*
Insert channel
*/
chnl := []interface{}{
bson.D{{"channel", "nouryqt"}},
bson.D{{"channel", "nourybot"}},
}
res, insertErr := collection.InsertMany(ctx, chnl)
if insertErr != nil {
log.Fatal(insertErr)
}
log.Info(res)
/*
Iterate a cursor
*/
cur, currErr := collection.Find(ctx, bson.D{})
if currErr != nil {
panic(currErr)
}
defer cur.Close(ctx)
var channels []Channel
if err = cur.All(ctx, &channels); err != nil {
panic(err)
}
log.Info(channels)
} }