1

I asked a question on Stackoverflow, and was told that my schema was way off. I am using mongodb to store whether or not a log file exists. The log file contains info for an hour. I'm not actually storing the file, just the file's name and the hour it represents. I'm also determining the existence of data for a given hour if that file exists in my db. I don't deny my document structure is bad, but:

  1. What is a better way to do the schema I have (below)? Each file represents an hour. The DB just has to know that a file exists for a specific day and hour. My webapp pulls this info to display available days and hours for the user.

  2. Why is my schema so bad?

Current document structure:

{ 
    _id   : "2014-02-13",
    hours : [
              { hour: "00", file: [
                     {name:"something.csv", date_added : ISODate("2014-04-04T08:59:34.268Z")}, 
                     {...},
                     {...}]
              },
              { hour: "01", file: [{},{}]},
              { hour: "04", file: [{},{}]} // some hours can be missing
            ]
}
  • Can you explain what you are storing in the 'file' array ? Have you see the blog post on time-series data (blog.mongodb.org/post/65517193370/…) and on storing log data (docs.mongodb.org/ecosystem/use-cases/storing-log-data) ? Can you explain a little more what you are trying to achieve with your app ? – eoinbrazil Apr 4 '14 at 14:50
  • Edited to explain better. I am not actually store the data from the file. And now, I haven't read either of those... from the first, it looks like I could try to implement a timestamp_hour or something? – Jeff Apr 4 '14 at 14:54
  • What is this representing ? Is this a set of predefined log files or can they be dynamically added ? I'm still not sure what you are trying to model with the schema, can you explain it a little deeper ? – eoinbrazil Apr 4 '14 at 15:01
  • Some other application (that I didn't write) runs and gives me these log files. I process them by finding out what hour they represent and storing the fact that a particular hour exists. – Jeff Apr 4 '14 at 15:14
-1

Is very bad for lots of registers... if you need accessing a file, need typing db.collection.find({"hours.hour":"05", "hours.file.name":"name"}). And you hours arrays will grow very fast...

You can having a struct like this,

{ 
    _id   : {date:"2014-02-13",hour: "00"}, files: [
                     {name:"something.csv", date_added : ISODate("2014-04-04T08:59:34.268Z")}, 
                     {...},
                     {...}]
 }

Having a documents with a array having little data and where you find very fast...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.