I currently have a collection ‘question’ with a document schema as follows:
_id: ObjectId("62e32a75a984c054fb986fd0"),
id: '19',
product_id: '3',
body: 'Why is this product cheaper here than other sites?',
date_written: '1590413602314',
asker_name: 'jbilas',
asker_email: 'first.last@gmail.com',
reported: '0',
helpful: '6',
answers: {}```
I am trying to update 'helpful' field to be an integer on every document in my collection. And am running this command:
db.question.updateMany({ }, [{ $set: { helpful: {$toInt: “$helpful”}}}])
And get this error message:
**MongoServerError:** Failed to parse number 'helpful' in $convert with no onError value: Did not consume whole string.
When I try to update one individually like this, It works successfully. Any tips on what I am doing wrong?
db.question.updateMany({id: “16” }, [{ $set: { helpful: {$toInt: “$helpful”}}}])