在此代碼中,我試圖根據(jù).但是每當(dāng)我運(yùn)行此代碼時(shí),它都會(huì)給我一個(gè)錯(cuò)誤.userIDmongo: no documents in result我也用mongo shell寫,但它給了我一個(gè)結(jié)果。盡管數(shù)據(jù)存在于MongoDB數(shù)據(jù)庫(kù)中。這是要看的圖片。db.dataStored.findOne({_id: ObjectId("60a60718503219dfd740f9fe")})nulluserID := "60a60718503219dfd740f9fe"var result Trainercollection := client.Database("PMS").Collection("dataStored")err = collection.FindOne(context.TODO(), bson.M{"_id": userID}).Decode(&result)if err != nil { log.Fatal(err)}fmt.Printf("Found a single document: %+v\n", result)
1 回答

呼如林
TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
您正在搜索字符串,但卻是一個(gè) ._id_idObjectId
objectId, err:=primitive.ObjectIDFromHex(userID)
collection.FindOne(context.TODO(), bson.M{"_id": objectId}).Decode(&result)
- 1 回答
- 0 關(guān)注
- 104 瀏覽
添加回答
舉報(bào)
0/150
提交
取消