- Url
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
});
To run tests (you must have a running instance of mongodb):
make test
MIT License
Brian Noguchi
Openify.it