by Robin at 20240316
This commit is contained in:
parent
fc6f81c29f
commit
4f609481cc
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue