I need to create some variation for the user, so that he can select only those users for whom he specifies a category (search by category) or those who do not have the same categories as in the array (in the code you can see the array). I used the documentation and found this answer: operator $ne
But it is not works, I get a list of all users
func (r *Mongo) User(ctx context.Context, query *domain.Query) ([]*User, error) {
var filter interface{}
if query.Query != "" {
filter = bson.D{primitive.E{Key: "status", Value: true}, primitive.E{Key: "category", Value: query.Query}}
} else {
filter = bson.D{primitive.E{Key: "status", Value: true}}
} - this works
if query.OtherCategory {
category := []string{"it", "medical", "sport"}
filter = bson.M{"status": true, "category": bson.M{"$ne": category}}
} - this it is not works
cursor, err := r.col.Find(ctx, filter, opts)
var results []*domain.User
if err = cursor.All(ctx, &results); err != nil {
r.logger.Error().Err(err).Msg("failed find")
return nil, err
}
return results, nil
}
How to make a query to get a list of users who don't have these (array of categories in the code) categories in the array, and their status is true?