code to create and delete groupMmber collection in DB
This commit is contained in:
@@ -166,6 +166,16 @@ func (s MongoDBStorage) CreateGroupMember(groupMember GroupMember) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) DeleteGroupMember(id string) error {
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["groups_member"])
|
||||
|
||||
if _, err := collection.DeleteOne(context.TODO(), bson.M{"_id": id}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetGroupMember(id string) (*GroupMember, error) {
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["groups_member"])
|
||||
|
||||
@@ -188,17 +198,17 @@ func (s MongoDBStorage) GetGroupsMember(namespaces []string) (groupsMember []Gro
|
||||
if err != nil {
|
||||
return groupsMember, err
|
||||
}
|
||||
// if len(namespaces) == 0 {
|
||||
// cur, err = collection.Find(context.TODO(), bson.D{}, findOptions)
|
||||
// if err != nil {
|
||||
// return groupsMember, err
|
||||
// }
|
||||
// } else {
|
||||
// cur, err = collection.Find(context.TODO(), bson.M{"namespace": bson.M{"$in": namespaces}}, findOptions)
|
||||
// if err != nil {
|
||||
// return groupsMember, err
|
||||
// }
|
||||
// }
|
||||
if len(namespaces) == 0 {
|
||||
cur, err = collection.Find(context.TODO(), bson.D{}, findOptions)
|
||||
if err != nil {
|
||||
return groupsMember, err
|
||||
}
|
||||
} else {
|
||||
cur, err = collection.Find(context.TODO(), bson.M{"groupid": bson.M{"$in": namespaces}}, findOptions)
|
||||
if err != nil {
|
||||
return groupsMember, err
|
||||
}
|
||||
}
|
||||
|
||||
for cur.Next(context.TODO()) {
|
||||
var group GroupMember
|
||||
@@ -228,7 +238,7 @@ func (s MongoDBStorage) GetGroupsMemberByIds(groupids []string) (groupsMember []
|
||||
if len(groupids) == 0 {
|
||||
return groupsMember, errors.New("no group id provided")
|
||||
} else {
|
||||
cur, err = collection.Find(context.TODO(), bson.M{"_id": bson.M{"$in": groupids}}, findOptions)
|
||||
cur, err = collection.Find(context.TODO(), bson.M{"groupid": bson.M{"$in": groupids}}, findOptions)
|
||||
if err != nil {
|
||||
return groupsMember, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user