Add workaround for empty SerraPrices on new Sets

This commit is contained in:
Florian Baumann 2022-08-18 08:21:31 +02:00
parent 880880df8e
commit de5d07e150
2 changed files with 15 additions and 4 deletions

View File

@ -50,13 +50,13 @@ func (coll Collection) storage_add(card *Card) error {
} }
func (coll Collection) storage_add_set(set *Set) error { func (coll Collection) storage_add_set(set *Set) (*mongo.InsertOneResult, error) {
_, err := coll.InsertOne(context.TODO(), set) id, err := coll.InsertOne(context.TODO(), set)
if err != nil { if err != nil {
return err return id, err
} }
return nil return &mongo.InsertOneResult{}, nil
} }

View File

@ -41,6 +41,17 @@ var updateCmd = &cobra.Command{
continue continue
} }
// Workaround for:
// "The field 'serra_prices' must be an array but is of type null in document"
// I dont know why I need to initialize this array alement as an empty array, but $push does
// not work on null fields.
if len(set.SerraPrices) == 0 {
set_init := bson.M{
"$set": bson.M{"serra_prices": bson.A{}},
}
setscoll.storage_update(bson.M{"code": bson.M{"$eq": set.Code}}, set_init)
}
bar := progressbar.NewOptions(len(cards), bar := progressbar.NewOptions(len(cards),
progressbar.OptionSetWidth(50), progressbar.OptionSetWidth(50),
progressbar.OptionSetDescription(fmt.Sprintf("%s, %s%s%s\t", set.ReleasedAt[0:4], Yellow, set.Code, Reset)), progressbar.OptionSetDescription(fmt.Sprintf("%s, %s%s%s\t", set.ReleasedAt[0:4], Yellow, set.Code, Reset)),