Mongo使用空的objectid引用保存文档-错误:JSON中的ObjectId无效

I'm working on golang server, connected to mongo.

I have a the following reference structure:

type A struct {
    Id   bson.ObjectId    `bson:"_id" json:"id"`
    B    bson.ObjectId    `bson:"b,omitempty" json:"b,omitempty"`
}

Thing is, B is not mandatory in A, and when ever I try to save A without B i'm getting an error:

"Invalid ObjectId in JSON: null"

How can I have this reference be no mandatory?

Can you try with:

type A struct {
    Id bson.ObjectId  `bson:"_id" json:"id"`
    B  *bson.ObjectId `bson:"b,omitempty" json:"b,omitempty"`
}