Search code examples
mongodbgobsonobjectid

What is the nil/zero value of bson.ObjectId


I was creating unary tests when I got stuck on the following situation:

  • I have an object that has a foreign key. For some reason, I need to switch the ID and it works. However, sometimes, I need to remove this ID. If I have an ID, I realise a certain action and if I don't, then nothing happens.

However, I can't find the way to set my bson.ObjectId as nil or zero.

Does anyone knows how to do or a work around?


Solution

  • Or you can use the primitive.NilObjectID

    NilObjectID is the zero value for ObjectID.