I am a beginner in mongo with go. I am trying to find one document where "username"
or email
will be matched. But can't figure out the way to implement this condition to filter.
Here is my document model:
type User struct {
Username string `json:"username" bson:"username"`
Email string `json:"email" bson:"email"`
Password string `json:"password" bson:"password"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}
And the query:
filter := bson.D{
{"username", user.Username},
{"$or": {"email", user.Email}},
}
err = userCollection.FindOne(context.TODO(), filter).Decode(&user)