在此代碼中,我根據(jù)電子郵件和密碼查找數(shù)據(jù)。但我想做另一件事,那就是使用 a 并逐個打印數(shù)組數(shù)據(jù)。for loopresult給定結果Found a single document: {Name:bilal Email:bilal@gmail.com Password:bilalo Business:computer company}預期成果Name:bilal Email:bilal@gmail.com 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條經(jīng)驗 獲得超9個贊
在循環(huán)之前嘗試此操作printf
fmt.Printf("Name:%v \nEmail:%v \nPassword:%v \nBusiness:%v \n", result.Name, result.Email, result.Password, result.Business)
- 1 回答
- 0 關注
- 77 瀏覽
添加回答
舉報
0/150
提交
取消