Reputation: 1109
I'm just getting into NoSQL databases specifically MongoDB. I worked with SQL for many years so I'm used to a more traditional approach.
I have a Json package that is used to store all the details I want to collect for a apartment. I guess my question is do I store this all as one record (document) or should I split it up into different collections/documents and join them together some how.
Here is an example of my json
{
"Title": "First Class 8 bedroom home- resort-Exceptional decor and furnishings",
"Description" : "The Address is an eight bedroom, five bathroom Orlando vacation rental that’s located at the Champions Gate Resort – just a few minutes from the main gates of Walt Disney World!/n When you stay on property at Champions Gate, you are privy to a variety of wonderful amenities that include but aren’t limited to, a large community pool, fitness center, club house, sports courts and two championship golf courses./n The resort amenities aren’t the only draw for this property because the vacation home alone is one to write home about./n The Address has everything that you could want and more when going on vacation. Why stay at an over-crowded hotel when you can spread out and relax inside of your own private home?/n This property didn’t leave any stones unturned because every room, every bit of décor was placed with care./n Just take the open-concept main living, dining and kitchen area. The cool, light blue wall connects all three spaces into one complete area. The blue is perfectly complemented by the whites and grays which make the first floor feel even more open!/n The kitchen is fully-equipped and outfitted with stainless steel appliances and granite countertops and a five-person breakfast bar./n Next to the kitchen is your main living area with three comfortable, leather couches and a large flat-screen TV./n Your dining room is also in this space and has a 12-person dining table which proves to be the perfect place to enjoy a family meal with your loved ones!/n Right off of this area, through a sliding glass door, is your private pool area. It’s here that you can enjoy the Orlando weather as you swim around in your private pool or soak in your Jacuzzi. The covered lanai will protect you and your guests from any unwanted bugs!/n Vacations are meant to be fun, right? Well, when you’re not at the nearby Orlando attractions like, Walt Disney World, Universal Studios or Sea World, or even splashing around in your own private pool or the resort’s community pool, you can keep the fun going in your games room!",
"images": [
"https://imagesus-ssl.homeaway.com/mda01/3381ed5a-f882-4efa-b246-b94f6de9618f.1.6",
"https://imagesus-ssl.homeaway.com/mda01/85a33780-4710-4815-b798-c6b6e6d0acc0.1.6",
"https://imagesus-ssl.homeaway.com/mda01/1caf0dab-9d78-45ae-910b-d4e7088d88cf.1.6",
"https://imagesus-ssl.homeaway.com/mda01/4123137e-086e-4171-9aad-d6aae14a7052.1.6"
],
"contact": {
"name": "James Privett",
"emailAddress": "[email protected]",
"skype": "james.privett",
"phone": "xxxxx xxxx"
},
"location": {
"name": "Orlando",
"latitude": 28.36433219,
"longitude": -81.55729782
},
"rooms" : [
{
"title": "Bedroom 1",
"image": "https://imagesus-ssl.homeaway.com/mda01/3381ed5a-f882-4efa-b246-b94f6de9618f.1.6",
"description": " <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, ut aliquip ex ea commodo consequat.</p> ",
"amenities": ["laundry","security","air conditioning","tv","satelite","open fire","swimming pool"]
},{
"title": "Bedroom 2",
"image": "https://imagesus-ssl.homeaway.com/mda01/85a33780-4710-4815-b798-c6b6e6d0acc0.1.6",
"description": " <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, ut aliquip ex ea commodo consequat.</p> ",
"amenities": ["laundry","security","air conditioning","tv","satelite","open fire","swimming pool"]
},{
"title": "Bedroom 3",
"image": "https://imagesus-ssl.homeaway.com/mda01/1caf0dab-9d78-45ae-910b-d4e7088d88cf.1.6",
"description": " <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, ut aliquip ex ea commodo consequat.</p> ",
"amenities": ["laundry","security","air conditioning","tv","satelite","open fire","swimming pool"]
}
]
}
Upvotes: 0
Views: 40
Reputation: 1006
@RudyVerboven had given a very good link for your question's answer but I would like to add some more points.
I would suggest you to go with embedded documents because this is one of the things in which MongoDB is performed very well. Since in the question you have mentioned if you will go for separate collection you will rely on joins but unlike SQL database MongoDB does not supports join other then single type of join which is left-outer equi-joins which was also added in MongoDB version 3.2.
Moreover, aggregation operations in MongoDB make working with embedded documents very easy due to the functions like unwind which can make nested documents as a separate document like in your example you can unwind your rooms array to make separate documents out of it and if required you can create separate collection of them using out function. Aside from you can also use indexing embedded fields for making queries faster and there are many more advantages also according to me MongoDb is designed to work with large chunks of embeded documents within the same collection with best optimization.
Upvotes: 1