mongodb-autoincrement icon indicating copy to clipboard operation
mongodb-autoincrement copied to clipboard

Cannot set initial values by mongo

Open ripper234 opened this issue 8 years ago • 1 comments

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...

ripper234 avatar Feb 19 '17 21:02 ripper234

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.

ripper234 avatar Feb 19 '17 21:02 ripper234