Created
January 23, 2013 15:35
-
-
Save xingrz/4608250 to your computer and use it in GitHub Desktop.
Seems to be a "best practice" of developing with [mongoose](http://mongoosejs.com).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose') | |
mongoose.connect('mongodb://localhost/mydb', function () { | |
console.log('mongodb connected') | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose') | |
, Schema = mongoose.Schema | |
, User = require('./user') | |
var TweetSchema = new Schema({ | |
sender: { type: Schema.Types.ObjectId, ref: User.modelName } | |
, content: { type: String, required: true } | |
}) | |
TweetSchema.virtual('created_at').get(function () { | |
return this._id.getTimestamp() | |
}) | |
module.exports = mongoose.model('Tweet', TweetSchema) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose') | |
, Schema = mongoose.Schema | |
var UserSchema = new Schema({ | |
username: { type: String, required: true, unique: true } | |
, password: { type: String, required: true } | |
}) | |
module.exports = mongoose.model('User', UserSchema) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment