type Student struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
...
Users []primitive.ObjectID `json:"users"`
...
}
I have this struct and I want to add to Users array. I'm doing this and I'm using Mongo-go-driver
// Filter for search
filter := bson.M{"_id": userID}
// Fields to update
update := bson.M{"$addToSet": bson.M{"users": ID}}
// Update the document
UsersCollection := GetUsersCollection()
UsersCollection.FindOneAndUpdate(context.Background(), filter, update, nil)
Can somebody tell me what I'm doing wrong? It's not adding to the database it's staying null.