在此代碼中,我根據電子郵件和密碼查找數據。但我想做另一件事,那就是使用 a 并逐個打印數組數據。for loopresult給定結果Found a single document: {Name:bilal Email:[email protected] Password:bilalo Business:computer company}預期成果Name:bilal Email:[email protected] Password:1234 Business:computer company法典// Find data in database based on email and passwordvar result Storecollection := client.Database("PMS").Collection("dataStored")if err = collection.FindOne(context.TODO(), bson.M{"email": myEmail, "password": myPassword}).Decode(&result); err != nil { log.Fatal(err)}fmt.Printf("Found a single document: %+v\n", result)for _, results := range &result { fmt.Println(results)}
1 回答

素胚勾勒不出你
TA貢獻1827條經驗 獲得超9個贊
在循環之前嘗試此操作printf
fmt.Printf("Name:%v \nEmail:%v \nPassword:%v \nBusiness:%v \n", result.Name, result.Email, result.Password, result.Business)
- 1 回答
- 0 關注
- 74 瀏覽
添加回答
舉報
0/150
提交
取消