{"id":19956429,"url":"https://github.com/drudge/mongoose-timestamp","last_synced_at":"2025-04-12T15:39:03.560Z","repository":{"id":5491222,"uuid":"6689476","full_name":"drudge/mongoose-timestamp","owner":"drudge","description":"Adds createdAt and updatedAt date attributes that get auto-assigned to the most recent create/update timestamp","archived":false,"fork":false,"pushed_at":"2022-04-07T03:02:44.000Z","size":64,"stargazers_count":309,"open_issues_count":17,"forks_count":64,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-04T13:49:09.894Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drudge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-14T15:06:51.000Z","updated_at":"2025-04-01T15:01:10.000Z","dependencies_parsed_at":"2022-09-05T05:30:41.287Z","dependency_job_id":null,"html_url":"https://github.com/drudge/mongoose-timestamp","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-timestamp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-timestamp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-timestamp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-timestamp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drudge","download_url":"https://codeload.github.com/drudge/mongoose-timestamp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248590640,"owners_count":21129865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T01:34:17.075Z","updated_at":"2025-04-12T15:39:03.532Z","avatar_url":"https://github.com/drudge.png","language":"JavaScript","funding_links":[],"categories":["⏱ Timestamps \u0026 Audit"],"sub_categories":[],"readme":"Mongoose Timestamps Plugin\n==========================\n\n[![Build Status](https://travis-ci.org/drudge/mongoose-timestamp.svg?branch=master)](https://travis-ci.org/drudge/mongoose-timestamp)\n[![Dependency Status](https://david-dm.org/drudge/mongoose-timestamp.svg)](https://david-dm.org/drudge/mongoose-timestamp)\n[![devDependency Status](https://david-dm.org/drudge/mongoose-timestamp/dev-status.svg)](https://david-dm.org/drudge/mongoose-timestamp#info=devDependencies)\n[![Downloads Monthly](https://img.shields.io/npm/dm/mongoose-timestamp.svg)](https://www.npmjs.com/package/mongoose-timestamp)\n[![Downloads Total](https://img.shields.io/npm/dt/mongoose-timestamp.svg)](https://www.npmjs.com/package/mongoose-timestamp)\n\nSimple plugin for [Mongoose](https://github.com/LearnBoost/mongoose) which adds `createdAt` and `updatedAt` date attributes\nthat get auto-assigned to the most recent create/update timestamp.\n\n## Installation\n\n`npm install mongoose-timestamp`\n\n## Usage\n\n```javascript\nvar timestamps = require('mongoose-timestamp');\nvar UserSchema = new Schema({\n    username: String\n});\nUserSchema.plugin(timestamps);\nmongoose.model('User', UserSchema);\nvar User = mongoose.model('User', UserSchema)\n```\nThe User model will now have `createdAt` and `updatedAt` properties, which get\nautomatically generated and updated when you save your document.\n\n```javascript\nvar user = new User({username: 'Prince'});\nuser.save(function (err) {\n  console.log(user.createdAt); // Should be approximately now\n  console.log(user.createdAt === user.updatedAt); // true\n  // Wait 1 second and then update the user\n  setTimeout( function () {\n    user.username = 'Symbol';\n    user.save( function (err) {\n      console.log(user.updatedAt); // Should be approximately createdAt + 1 second\n      console.log(user.createdAt \u003c user.updatedAt); // true\n    });\n  }, 1000);\n});\n```\n#### findOneAndModify (mongoose \u003e= 4.0.1)\n\nMongoose 4.0.1 added support for findOneAndModify hooks. You must the mongoose promise exec for the hooks to work as mongoose uses mquery when a callback is passed and the hook system is bypassed.\n\n```javascript\nUser.findOneAndUpdate({username: 'Prince'}, { password: 'goatcheese' }, { new: true, upsert: true })\n            .exec(function (err, updated) {\n                console.log(user.updatedAt); // Should be approximately createdAt + 1 second\n                console.log(user.createdAt \u003c user.updatedAt); // true\n            });\n```\n\nYou can specify custom property names by passing them in as options like this:\n\n```javascript\nmongoose.plugin(timestamps,  {\n  createdAt: 'created_at',\n  updatedAt: 'updated_at'\n});\n```\n\nAny model's updatedAt attribute can be updated to the current time using `touch()`.\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012-2016 Nicholas Penree \u0026lt;nick@penree.com\u0026gt;\n\nBased on [mongoose-types](https://github.com/bnoguchi/mongoose-types): Copyright (c) 2012 [Brian Noguchi](https://github.com/bnoguchi)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrudge%2Fmongoose-timestamp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrudge%2Fmongoose-timestamp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrudge%2Fmongoose-timestamp/lists"}