# goodeggs-mongoose-timestamps

> Adds createdAt and updatedAt fields to any schema

Latest version **2.1.0** (published 2021-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install goodeggs-mongoose-timestamps
pnpm add goodeggs-mongoose-timestamps
yarn add goodeggs-mongoose-timestamps
bun add goodeggs-mongoose-timestamps
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2021-01-21 |
| First published | 2015-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Good Eggs |
| Maintainers | goodeggs-admin, asalant |
| Keywords | mongoose plugin |

## Links

- npm: https://www.npmjs.com/package/goodeggs-mongoose-timestamps
- Repository: https://github.com/goodeggs/goodeggs-mongoose-timestamps
- Issues: https://github.com/goodeggs/goodeggs-mongoose-timestamps/issues
- npm.io page: https://npm.io/package/goodeggs-mongoose-timestamps

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2021-01-21
- 1.0.0 — 2015-01-23

## README

# goodeggs-mongoose-timestamps

Adds createdAt and updatedAt fields to any schema using Mongoose's built-in [timestamps schema option](http://mongoosejs.com/docs/guide.html#timestamps).

[![NPM version](http://img.shields.io/npm/v/goodeggs-mongoose-timestamps.svg?style=flat-square)](https://www.npmjs.org/package/goodeggs-mongoose-timestamps)
[![Build Status](http://img.shields.io/travis/goodeggs/goodeggs-mongoose-timestamps.svg?style=flat-square)](https://travis-ci.org/goodeggs/goodeggs-mongoose-timestamps)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/goodeggs/goodeggs-mongoose-timestamps/blob/master/LICENSE.md)

## Usage

```
npm install goodeggs-mongoose-timestamps
```

```coffee
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:

```coffee
# 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](https://docs.mongodb.com/manual/reference/bson-types/#objectid).

## 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`](http://sinonjs.org/docs/#clock-api).

## Contributing

Please follow our [Code of Conduct](https://github.com/goodeggs/goodeggs-mongoose-timestamps/blob/master/CODE_OF_CONDUCT.md)
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](https://github.com/goodeggs/generator-goodeggs-npm)._

## Releasing

For authorized authors:

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

---
_Source: https://npm.io/package/goodeggs-mongoose-timestamps · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
