This is my actuall code:
type usernameOnly struct {
username string `bson:"username"`
}
var user usernameOnly
users.FindOne(ctx, bson.M{"username": "kotcich"}).SetProjection(bson.M{"username": 1}).Decode(&user)
But i’m getting this error:
users.FindOne(ctx, (bson.M literal)).SetProjection undefined (type *mongo.SingleResult has no field or method SetProjection)
I just want to do it simple. I’ve seen example in official doc
, but it’s too complicated.
Basic usage FindOne with golang from offical doc look like this:
var podcast bson.M
podcastsCollection.FindOne(ctx, bson.M{}).Decode(&podcast);
So… i don’t really unserstand, why i can’t just add SetProjection to FindOne like 1 query. Or i’m missing something?