
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
mongoose-for-types
Advanced tools
createdAt and updatedAt date attributes that get auto-assigned to the most recent create/update timestamp.npm install mongoose-types
To include all of the defined types:
var mongoose = require("mongoose");
var db = mongoose.createConnection("mongodb://localhost/sampledb");
var mongooseTypes = require("mongoose-types");
mongooseTypes.loadTypes(mongoose);
You can also specify that you only want to load and use a limited subset of the types provided:
var mongoose = require("mongoose");
var db = mongoose.createConnection("mongodb://localhost/sampledb");
var mongooseTypes = require("mongoose-types");
// Only load the email type
mongooseTypes.loadTypes(mongoose, "email");
Once you are setup, you can begin to use the new types.
var Email = mongoose.SchemaTypes.Email;
var UserSchema = new Schema({
email: {
work: Email
, home: Email
}
});
var Url = mongoose.SchemaTypes.Url;
var VisitSchema = new Schema({
url: Url
, referer: Url
});
useTimestamps pluginvar mongoose = require("mongoose");
var db = mongoose.createConnection("mongodb://localhost/sampledb");
var mongooseTypes = require("mongoose-types")
, useTimestamps = mongooseTypes.useTimestamps;
var UserSchema = new Schema({
username: String
});
UserSchema.plugin(useTimestamps);
mongoose.model('User', UserSchema);
var User = db.model('User', UserSchema);
var user = new User({username: 'Prince'});
user.save(function (err) {
console.log(user.createdAt); // Should be approximately now
console.log(user.createdAt === user.updatedAt); // true
// Wait 1 second and then update the user
setTimeout( function () {
user.username = 'Symbol';
user.save( function (err) {
console.log(user.updatedAt); // Should be approximately createdAt + 1 second
console.log(user.createdAt < user.updatedAt); // true
});
}, 1000);
});
To run tests:
make test
MIT License
Brian Noguchi
FAQs
More types for mongoose
We found that mongoose-for-types demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.