【发布时间】:2022-01-02 01:25:29
【问题描述】:
我正在 nodejs 中构建房间预订系统。目前我有 hotels , rooms 和 bookings 作为集合。
rooms 引用 hotels,bookings 引用 rooms。
booking.js
const bookingSchema = new mongoose.Schema({
room: {
type: mongoose.Schema.Types.ObjectId,
ref: 'rooms'
},
start: Date,
end: Date
});
rooms.js
const roomSchema = new mongoose.Schema({
roomid: String,
hotel: {
type: mongoose.Schema.Types.ObjectId,
ref: 'hotel_managers'
},
type: String,
price: Number,
capacity: Number,
facilities: [String],
amenities: [String],
img: [String]
});
hotels.js
const hotel_manager_schema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
hotelname: {
type: String,
required: true
},
role: {
type: String,
default: 'manager'
},
location: {
type: String,
required: true
},
img:{
type: String,
required: true
}
})
注意这是一个服务提供商端的系统,因此酒店基本上是具有其凭据的酒店经理。
我想要实现的是,当用户发送给定日期范围的查询时,我想返回所有可用的酒店以及在查询日期范围内没有任何预订的酒店中的房间。
我是 MongoDB 的新手,所以任何关于如何做我想做的事的提示或建议都会有很大帮助。
【问题讨论】: