Socket
Book a DemoInstallSign in
Socket

goodeggs-mongoose-timestamps

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

goodeggs-mongoose-timestamps

Adds createdAt and updatedAt fields to any schema

latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
2
Created
Source

goodeggs-mongoose-timestamps

Adds createdAt and updatedAt fields to any schema using Mongoose's built-in timestamps schema option.

NPM version Build Status MIT License

Usage

npm install goodeggs-mongoose-timestamps
timestamps = require 'goodeggs-mongoose-timestamps'

schema = new mongoose.Schema {}
schema.plugin timestamps

Indexes

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.

Dependencies

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.

Testing

To stub the values used to timestamp Mongoose objects, use sinon.useFakeTimers.

Contributing

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.

Releasing

For authorized authors:

git co master && git pull
npm version [major|minor|patch]
git push --follow-tags
npm publish

Keywords

mongoose plugin

FAQs

Package last updated on 21 Jan 2021

Did you know?

Socket

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.

Install

Related posts