Skip to content

Instantly share code, notes, and snippets.

@xingrz
Created January 23, 2013 15:35
Show Gist options
  • Save xingrz/4608250 to your computer and use it in GitHub Desktop.
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).
var mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/mydb', function () {
console.log('mongodb connected')
})
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)
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