I've been working on a project that uses mongodb to store data. In the past I've always used SQL but thought I would try our mongodb. Now that the code is written and the site is live and running I'm starting to wonder if I designed the db efficiently. The whole site uses one schema but I'm wondering if it would have been cleaner to use multiple schema.
The accounts[].reservations[]
, accounts[].listings[].messages[]
and accounts[].listings[].prices[]
are going to get really large and I've found that because I have so many objects inside of arrays of objects it's difficult to set/update things. How could I lay this out better?
Here's what I got:
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
]
});
I just recently open sourced the project if you want to check out more the the code. It's an auto messaging and pricing engine for airbnb hosts: