filter:= bson.D {{“ hello”,“ world”}}代替使用值(世界),我如何传递包含该值(世界)的变量[关闭]

While fetching particular from mongodb using Go, eg:

filter := bson.D{{"hello", "world"}}

in this, instead of passing value (world), how can I pass a variable which contain the value(world)?

username:=r.FormValue("username")
filter := bson.D{{"username", '$username'}}

I don't really understand your question, but it seems like this should work, if you want to use a variable instead of a string literal.

username := "bob"
filter := bson.D{{"username", username}}

This is the absolute simplest use of a variable, though, which makes me think you must be getting at something more complicated. Please clarify your question if you need more than this.