Models实体的创建

项目采用mongoose来操作数据库。首先就是创建一个实体,于Mongodb中的表相对应,进行映射。

房间实体:

var mongoose=require('mongoose');
var schema=new mongoose.Schema({
    Name:String,
    BigCategory:String, //房间类别
    SmallCategory:String, //房间类别
    Img:String,
    CreateTime:Date,
    UserId:String
});
module.exports=mongoose.model('Rooms',schema);

用户实体:

var mongoose=require('mongoose');
mongoose.connect('mongodb://localhost/liveroom_app');
var schema=new mongoose.Schema({
    Name:String,
    UserName:String,
    PhoneNumber:String,
    IdCard:String,
    Identity:String,
    CreateTime:Date,
    PassWord:String,
});
module.exports=mongoose.model('Users',schema);

 

posted @ 2016-12-16 09:57  8932809  阅读(199)  评论(0编辑  收藏  举报