mirror of
https://github.com/sstent/expressmongotest.git
synced 2026-01-26 17:12:33 +00:00
added article
This commit is contained in:
20
test/data/schemas/article.js
Normal file
20
test/data/schemas/article.js
Normal file
@@ -0,0 +1,20 @@
|
||||
var Schema = require('mongoose').Schema;
|
||||
|
||||
var ArticleSchema = new Schema({
|
||||
title: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
body: String,
|
||||
author: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
required: true
|
||||
},
|
||||
created_at: {
|
||||
type: Date,
|
||||
'default': Date.now
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ArticleSchema;
|
||||
17
test/data/schemas/user.js
Normal file
17
test/data/schemas/user.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var UserSchema = new mongoose.Schema({
|
||||
username: {type: String, unique: true},
|
||||
name: String,
|
||||
password: String,
|
||||
});
|
||||
|
||||
UserSchema.methods.recentArticles = function(callback) {
|
||||
return this.model('Article')
|
||||
.find({author: this._id})
|
||||
//.sort('created_at', 1)
|
||||
.limit(5)
|
||||
.exec(callback);
|
||||
};
|
||||
|
||||
module.exports = UserSchema;
|
||||
Reference in New Issue
Block a user