Mongoose 模型使用

ki0zmccv  于 2023-06-23  发布在  Go
关注(0)|答案(1)|浏览(119)

我正在尝试在我的系统中构建mongodb模型。我在我的业务模型中保留了以下信息:

const BussinessSchema = new Schema({
    bussinesId: {type: String},
    bussinessSubId: {type: String},
    subscriptionId: {type: String},
    accesId:{type:String},
    country: {type:String},
    city: {type:String},
    street: {type:String},
    products:[{productId: Number, role: Number, 
        dayOfDay:[{day: Date}], reservations:[{customerName:String, customerSurname:String,
             phoneNumber:Number,date: Date }]}],
})

过了一段时间,我认为预订字段会膨胀,因为它会占用太多的数据。我能做些什么来防止这种情况?我不想删除数据。有没有一种方法可以更有效地存储这些数据?

yh2wf1be

yh2wf1be1#

const BussinessSchema = new Schema({
    bussinesId: {type: String},
    bussinessSubId: {type: String},
    subscriptionId: {type: String},
    accesId:{type:String},
    country: {type:String},
    city: {type:String},
    street: {type:String},
    products:[
      {productId: Number,
      role: Number, 
        dayOfDay:[{day: Date}],
        reservations:[
          {customerName:String, 
          customerSurname:String,
             phoneNumber:Number,
             date: Date 
            
          }
         ]
      }
    ],
})

完成此操作后,您必须创建一个模型

const Bussiness = mongoose.model('Bussiness', BussinessSchema);
//now you can further use this object for data manuplation on this model like

Bussiness.findOne({bussinesId:passId})

相关问题