-
-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: mongodb _id must be a string #7255
Conversation
Kudos, SonarCloud Quality Gate passed! |
# see bug #1077 - https://github.com/openfoodfacts/openfoodfacts-server/issues/1077 | ||
# make sure that code is saved as a string, otherwise mongodb saves it as number, and leading 0s are removed | ||
$product_ref->{code} = $product_ref->{code} . ''; | ||
$product_ref->{_id} .= ''; | ||
$product_ref->{code} .= ''; | ||
$products_collection->replace_one({"_id" => $product_ref->{_id}}, $product_ref, { upsert => 1 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should'nt we refactor and have an upsert_product function that ensure this kind of thing ? (Instead of using replace_one directly). This may help avoiding this error and maybe others ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was an issue for barcode changes, the mongodb _id field got a number long type instead of a string.
This:
Once deployed, we need to:
run ./update_all_products.pl --fix-non-string
issue the MongoDB command indicated at the end of the script run:
products stored in MongoDB with a non string _id have been reloaded from .sto files (if the products still exist) and stored with a string _id.
products with non string ids can now be deleted from MongoDB with this command:
db.products.remove({_id : { $type : "long" }})
Fixes #4667