Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 526
Emixam23 Avatar asked Oct 20 '25 02:10

Emixam23


2 Answers

Or you can use the primitive.NilObjectID

NilObjectID is the zero value for ObjectID.

like image 185
Bastien Avatar answered Oct 22 '25 16:10

Bastien


bson.ObjectId is an alias for string , therefore the zero value is an empty string ""

like image 45
Mostafa Solati Avatar answered Oct 22 '25 17:10

Mostafa Solati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!