First this is mongodb's data.
{
_id : 1,
"Test1" : "Hello",
"Test2" : "MongoDB!",
}
And this is golang struct.
type P_SET struct {
_id int
Test1 string
Test2 string
}
Next this is my golang code.
var pol P_SET
collection := client.Database("DBName").Collection("CollectionName")
err := collection.FindOne(context.TODO(), bson.M{"_id": 1}).Decode(&pol)
But the result does not come with only _id
data.
&{0, "Hello", "MongoDB!"}
I wonder why I can't get only _id
values.