by Robin at 20240316

This commit is contained in:
Leufolium 2024-03-16 23:54:18 +08:00
parent fc6f81c29f
commit 4f609481cc
2 changed files with 22 additions and 2 deletions

View File

@ -18,8 +18,11 @@ func main() {
}
ctx := context.Background()
account, _ := client.GetAccountListByMid(ctx, 2)
if account != nil {
list, _ := client.GetAccountList(ctx)
fmt.Printf("共%v个account待更新", len(list))
for _, account := range list {
account.UserIdString = goproto.String(fmt.Sprint(*account.UserId))
client.UpdateAccount(ctx, account)
}

View File

@ -152,6 +152,23 @@ func (m *Mongo) GetAccountListByMid(ctx context.Context, mid int64) (*dbstruct.A
return account, err
}
func (m *Mongo) GetAccountList(ctx context.Context) ([]*dbstruct.Account, error) {
col := m.getColAccount()
list := make([]*dbstruct.Account, 0)
query := qmgo.M{}
err := col.Find(ctx, query).All(&list)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, err
}
if err != nil {
return nil, err
}
return list, err
}
func (m *Mongo) UpdateAccount(ctx context.Context, account *dbstruct.Account) error {
col := m.getColAccount()
set := qmgo.M{