mongodb-autoincrement
mongodb-autoincrement copied to clipboard
Cannot set initial values by mongo
I'm sure this is not a bug, I just don't understand something.
You wrote
You cannot set initial values for auto increment fields by the module. If you need it you can always set them directly via mongodb. Find a record with _id 'collectionName' in the collection 'counters' and set field 'seq' to required value.
I am trying to do just that. However I find zero such records, even though while the module is working. In addition, I'm inserting such records, and the module ignores them:
mongoose.connect(mongouri).then(() => {
console.log('Setting initial ID to 0')
mongoose.connection.db.collection('counters').save(
{
'_id': 'collectionName',
'seq': 0
}
)
}
What am I missing? How does the module even work?
Again, my test database only contains a couple of objects with _ids autogenerated by the module, but no counters collection...
P.S I tried passing new mongoose.mongo.ObjectId('000000000000000000000000') } instead of 0 as 'seq' as well. Two separate issues here: 1. Why aren't I seeing any counters table in the DB when I manually look for it, and then 2. Is my code to reset it ok / why not.