使用MongoDB和Mongoose进行建模

时间:2015-06-09 14:52:11

标签: mongodb mongoose nosql

我有一个简单的应用程序,其中列出了用户关于每个指南的导游和评论。任何用户都可以作为指南并提供评论。我的用户计划是:

var User = new mongoose.Schema({ 
    firstName: { type: String, required: true, unique: true },
    lastName: { type: String, required: true, unique: true },
    email: { type: String, required: true, unique: true },
    password: { type: String, required: true}   
    isGuide: Boolean,
    rating: {type: Number, "default": 0, min: 0, max: 5},
    reviews: [reviewSchema]
});


var Review = new mongoose.Schema({
    userId: {type: Schema.ObjectId, ref: 'User'},
    author: {type: String, required: true},//contatenation of firstName and lastName of user that wrote review
    rating: {type: Number, required: true, min: 0, max: 5},
    reviewText: {type: String, required: true},
    createdOn: {type: Date, "default": Date.now}
});

mongoose.model('User', User);

我希望能够:

1 /显示指南和所有指南的评论 2 /显示所有用户的评论 3 /显示用户已查看的所有指南

我认为上面的模式适用于1.但是它适合2和3吗?我是否正确理解了MonboDB的理念?

0 个答案:

没有答案