我try 让Get All Data With Name字段在API请求正文中指定的位置.我为.Find()函数制作了一个过滤器.但我无法获得任何结果(响应正文显示为空,根本没有错误).您可以在底部看到我的模型文件和代码的其他部分.
Controller:个
func GET_FormByPatientFullName(ctx *gin.Context) {
col := mongodb.CLIENT.Database(config.DATABASE_NAME).Collection("consentforms")
filter := bson.M{"Patient": bson.M{"Name": ctx.Query("name")}}
cursor, err := col.Find(_CONTEXT.TODO(), filter)
if err != nil {
log.Fatal(err)
}
var results []general_models.ConsentForm
if err = cursor.All(_CONTEXT.TODO(), &results); err != nil {
log.Fatal(err)
}
for _, result := range results {
res, _ := json.Marshal(result)
fmt.Println(string(res))
}
ctx.IndentedJSON(http.StatusOK, gin.H{"data": results})
}
Model File:个
type ConsentForm struct {
ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
FormFileURL string `json:"FormFileURL" bson:"FormFileURL"`
ProcessName string `json:"ProcessName" bson:"ProcessName"`
DateOfNotification string `json:"DateOfNotification" bson:"DateOfNotification"`
WitnessName string `json:"WitnessName" bson:"WitnessName"`
WitnessSurname string `json:"WitnessSurname" bson:"WitnessSurname"`
ResponsibleDoctor string `json:"ResponsibleDoctor" bson:"ResponsibleDoctor"`
Patient IPatient `json:"Patient" bson:"Patient"`
QuestionOptions IQuestionOptions `json:"QuestionOptions" bson:"QuestionOptions"`
AdditionalDetails string `json:"AdditionalDetails" bson:"AdditionalDetails"`
}
type IPatient struct {
// ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
Name string `json:"Name" bson:"Name"`
Surname string `json:"Surname" bson:"Surname"`
Birthdate string `json:"Birthdate" bson:"Birthdate"`
TCKN string `json:"TCKN" bson:"TCKN"`
FacePhotoURL string `json:"FacePhotoURL" bson:"FacePhotoURL"`
SignatureImageURL string `json:"SignatureImageURL" bson:"SignatureImageURL"`
}
我试图根据用户名过滤并获取该用户的所有数据.但我认为我在筛选器部分或整个代码中有错误,因为我无法获得任何数据返回.我得到的回报是空的.