Mongodb Date strings and other issues

mongodbschema

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
            ]
}

Best Answer

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...