Skip to content

incorrect calculating time when record expiredAt #115

@itbali

Description

@itbali

this are me settings:

import { ConfigService } from '@nestjs/config';
import { ThrottlerStorageMongoService } from 'nestjs-throttler-storage-mongo';
import { getMongoConfigs } from './get-mongo.configs';
import { seconds } from '@nestjs/throttler';

export const configThrottlingWithMongoRec = (config: ConfigService) => {
  const ttlInMilliseconds = seconds(config.get('THROTTLE_TTL')); // Convert ttl to milliseconds
  const expireAt = new Date(Date.now() + ttlInMilliseconds); // Calculate expireAt based on current time

  console.log('configThrottlingWithMongoRec', {
    uri: getMongoConfigs(config).uri,
    ttl: ttlInMilliseconds,
    limit: +config.get('THROTTLE_LIMIT'),
    expireAt,
  });

  return {
    storage: new ThrottlerStorageMongoService(getMongoConfigs(config).uri),
    throttlers: [
      {
        ttl: ttlInMilliseconds, // Use ttl in milliseconds for storage
        limit: +config.get('THROTTLE_LIMIT'),
      },
    ],
  };
};

result of console.log:

configThrottlingWithMongoRec {
  uri: 'mongodb+srv://admin:[email protected]/shoplist',
  ttl: 5000,
  limit: 5,
  expireAt: 2024-05-08T12:47:01.051Z
}

this is what i receive in Mongo:

  "_id": {
    "$oid": "663b745957f26e53877db200"
  },
  "key": "064a679b470bf496d5d7da6efbe6bf56",
  "expireAt": {
    "$date": "2024-05-08T14:11:00.100Z"
  },
  "totalHits": 10
}```


expected to see expireAt in mongo same as in console.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions