mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
get name
This commit is contained in:
parent
5279e772d1
commit
26a7a26115
1 changed files with 28 additions and 14 deletions
|
@ -48,33 +48,47 @@ func Connect() {
|
|||
/*
|
||||
Insert channel
|
||||
*/
|
||||
chnl := []interface{}{
|
||||
bson.D{{"channel", "nouryqt"}},
|
||||
bson.D{{"channel", "nourybot"}},
|
||||
}
|
||||
// chnl := []interface{}{
|
||||
// bson.D{{"name", "nouryqt"}},
|
||||
// bson.D{{"name", "nourybot"}},
|
||||
// }
|
||||
|
||||
res, insertErr := collection.InsertMany(ctx, chnl)
|
||||
if insertErr != nil {
|
||||
log.Fatal(insertErr)
|
||||
}
|
||||
log.Info(res)
|
||||
// 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{})
|
||||
// var result bson.M
|
||||
// err = collection.FindOne(ctx, bson.D{{}}).Decode(&result)
|
||||
// if err != nil {
|
||||
// if err == mongo.ErrNoDocuments {
|
||||
// return
|
||||
// }
|
||||
|
||||
// panic(err)
|
||||
// }
|
||||
// log.Info(result["name"])
|
||||
|
||||
//------------------------------
|
||||
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 {
|
||||
var results []bson.M
|
||||
if err = cur.All(ctx, &results); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Info(channels)
|
||||
|
||||
for _, result := range results {
|
||||
fmt.Println(result["name"])
|
||||
}
|
||||
//------------------------------
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue