mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
insert and load channel
This commit is contained in:
parent
203f921c18
commit
5279e772d1
|
@ -35,4 +35,46 @@ func Connect() {
|
|||
}
|
||||
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)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue