mongoose - mongodb, 商家数据库schema如何建立?
習慣沉默
習慣沉默 2017-05-02 09:19:30
0
1
824

简化来说,一个shop一般有一些属性类似:
那么在对这个schema进行操作的时候,通常是有一个账户来访问node.js里面的路由。

比如账户名称是shopName,密码是password

但是现实情况是,一个店铺可以有好几个帐号,帐号之间的权限会不一样。比如,店小二的帐号权限只能添加一个商品。而老板的帐号权限可以删除一个订单。

这个在mongodb里面实现的大致思路是什么呢?

module.exports = function( mongoose) {
  var ShopSchema = new mongoose.Schema({
    shopName:     { type: String, unique: true },
    password:{type:String},
    address:     { type: String},
    location:{type:[Number],index: '2d'},
    shopPicUrl:      {type: String},
    shopPicTrueUrl:{type: String},
    mark:  { type: String},
    open:{type:Boolean},
    shopType:{type:String},
    
    dish:{type:[DishSchema]},

    order:{type:[{
      orderId:{type: String},
      date:{type: Date,default: Date.now},
      dish:{type: [DishSchema]},
      userId:{type: String}
    }]}
    
  });

var DishSchema = new mongoose.Schema({
  dishName: { type: String},
      tags: { type: Array},
      price: { type: Number},
      intro: { type: String},
      dishPic:{ type: String},
      index:{type:Number},
      comment:{type:[{
        date:{type: Date,default: Date.now},
        userId:{type: String},
        content:{type: String}
      }]}
    });
習慣沉默
習慣沉默

reply all(1)
左手右手慢动作

The store is a separate account. An array is created below to record the username, password and login permissions.
{
shopname:XXXXX,
accounts:[
{

loginname:xxxx,
password:xxxx,
authority:[],

}]
}
Then create an index accouts.loginname unique
If you use mongo, think in the mongo way. Many of the current ODMs are designed with ORM ideas, and I prefer not to use them. Write json directly
Of course, you can stuff the user’s detailed information into the login name layer, such as avatar introduction, etc. You can also create a table

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template