Roaders
Roaders

Reputation: 4545

Creating my first NoSQL database - avoiding duplication of data?

I am in the process of setting up my first mongoDB database to store temperature readings for various rooms in my house. Initially I will store values for the bedroom, living room and outside every 10 minutes. Each record will look something like this:

{
    name: "Living Room",
    key: "livingRoom",
    temp: 17.6
}

In a relationship database I would probably create a rooms table and a temperatureReadings table. The name would be stored in the rooms table and the temperature would be stored in the temperatureReadings table.

Am I correct in thinking that I should just store this object in one collection and just deal with the fact that I will be storing thousands of identical names?

Whilst space isn't a big concern this will be running on a raspberry pi without that much space and if it's running for 10 years then it might get to be quite large eventually.

Thanks.

Upvotes: 0

Views: 113

Answers (1)

Murwa
Murwa

Reputation: 2278

Yes, you just need a single collection. However, u can avoid dealing

with the fact that I will be storing thousands of identical names

by making temp an array of temperature readings. You final structure will be:-

{
    name: "Living Room",
    key: "livingRoom",
    temp: [{value: 17.6}, ...]
}

You can as well add the timestamp for your readings

Upvotes: 1

Related Questions