'Mongosh(shell) assign unique increasing number to every document
For the purpose of a product number, how can I assign an integer counting upwards starting with 001 to every document using mongo-shell?
As a results every document should have a unique "number" field.
My starting point is of course using updateMany().
db.items.updateMany({}, {$set: {number: [xxx]}})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
