我一直致力于使用mongodb存储数据的项目。在过去,我总是使用SQL,但我想我会尝试我们的mongodb。既然编写了代码并且站点正在运行并且正在运行,那我就开始怀疑我是否有效地设计了数据库。整个站点使用一个模式,但我想知道使用多个模式是否更清晰。
accounts[].reservations[]
,accounts[].listings[].messages[]
和accounts[].listings[].prices[]
会变得非常大,而且我发现因为我在对象数组中有很多对象,所以'很难设置/更新东西。我怎么能更好地解决这个问题?
这是我得到的:
var Account = new Schema({
username: String,
password: String,
created: {type: Date, default:Date.now},
accounts: [
{
type: {type: String, default: "Airbnb"}, // Airbnb, VRBO....
airbnbUsername: String,
airbnbPassword: String,
airbnbUserID: String,
airbnbAccessToken: String,
lastLoginAttemptSuccessful: {type: Boolean, default: false},
listings: [
{
id: String,
airbnbName: String,
airbnbCheckInTime: Number,
airbnbCheckOutTime: Number,
airbnbListingID: String,
airbnbTimeZone: String,
nickname: String,
pricesUpdatedLast: Date,
pricingEnabled: {type: Boolean, default: false},
minPrice: Number,
rules: {
messages: [
{
message: String,
title: String,
event: String,
days: Number,
time: Number,
minNights: {type: Number, default: 1},
lastMinuteMessage: {type: String, default: ""},
lastMinuteMessageEnabled: {type: Boolean, default: false},
reviewEnabled: {type: Boolean, default: false},
reviewMessage: String,
sendMessageAfterLeavingReview: Boolean,
}
], // messages
pricing: [
{
title: String,
scale: String, //(Fixed Value, Gradual Value, Fixed Percentage, Gradual Percentage)
amount: Number,
event: String, // floatingPeriod, orphanPeriod, specificDates, weekends, weekdays
floatingPeriodStartDay: Number,
floatingPeriodLength: Number,
orphanPeriodLength: Number,
specificDatesStartDate: Date,
specificDatesEndDate: Date,
}
] // pricing
}, // rules
messages: [
{
messageRuleID: String,
airbnbConfirmationCode: String,
disable: {type: Boolean, default:false},
message: String,
sentDate: Date,
sentEvent: String,
sentDateFormated: String,
sentTimeFormated: String,
review: String,
}
], // messages
prices: [
{
created: {type: Date, default:Date.now},
airbnbDate: String,
airbnbNativePrice: Number,
airbnbNativeSuggestedPrice: Number,
airbnbNativeSuggestedPricePercentage: Number,
airbnbNativeSuggestedPriceLevels: [{type: Number}],
airbnbAvailable: Boolean,
}
] // prices
}
], // listings
reservations: [
{
airbnbThreadID: String,
airbnbConfirmationCode: String,
airbnbListingID: String,
airbnbStartDate: String,
airbnbNights: Number,
airbnbFirstName: String,
airbnbStatus: String,
airbnbThumbnailUrl: String,
}
] // reservations
} // accounts
]
});
如果您想查看更多代码,我最近刚开源该项目。它是auto messaging and pricing engine for airbnb hosts: