
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
goodeggs-mongoose-timestamps
Advanced tools
Adds createdAt and updatedAt fields to any schema using Mongoose's built-in timestamps schema option.
npm install goodeggs-mongoose-timestamps
timestamps = require 'goodeggs-mongoose-timestamps'
schema = new mongoose.Schema {}
schema.plugin timestamps
By default, it creates an index for updatedAt with spec {updatedAt: 1}. To override
this behavior:
# Creates indexes for updatedAt by default
schema.plugin timestamps
# Does not create indexes
schema.plugin timestamps, createIndexes: false
# Only create createdAt index, descending order
schema.plugin timestamps, createIndexes: {createdAt: -1}
Note that it does not create an index on createdAt. An index on createdAt is redundant with the index already on _id which encodes the document create time
in the first 4 bytes.
This module does not pull in an other dependencies but does require that your application is using Mongoose 4.4.7 or greater. That was the version that first supported setting the timestamps option directly on the schema with set rather than in the schema constructor.
To stub the values used to timestamp Mongoose objects, use sinon.useFakeTimers.
Please follow our Code of Conduct when contributing to this project.
$ git clone https://github.com/goodeggs/goodeggs-mongoose-timestamps && cd goodeggs-mongoose-timestamps
$ npm install
$ npm test
Module scaffold generated by generator-goodeggs-npm.
For authorized authors:
git co master && git pull
npm version [major|minor|patch]
git push --follow-tags
npm publish
FAQs
Adds createdAt and updatedAt fields to any schema
We found that goodeggs-mongoose-timestamps demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.