I am a Mongo DB beginner.
I have to create a collection that can store events. All the documents in the Event will have a FROM_TIME and TO_TIME keys whose values can vary as follows :
Given the random occurrence of the FROM_TIME and TO_TIME, will it be possible to query for events like :
I request people here to provide leads in case I need to rethink the structure of my collection as I'm quite naive at Mongo(or any other non-relational)DB.
***1st Edit begins here
I wrote the following code:
DBObject dbObject = new BasicDBObject();
dbObject.put("EVNTATMC_ID", new ObjectId());
dbObject.put("EVNTATMC_DESC", "Pearl Harbour");
dbObject.put("EVNTATMC_FROM_TIME", Date.valueOf("1944-12-07"));
dbObject.put("EVNTATMC_TO_TIME", Date.valueOf("1944-12-07"));
dbObject.put("EVNTATMC_EVNTCMPD_ID", new ObjectId());
dbObject.put("EVNTATMC_MTRL_ID", null);
// dbObject.put("EVNTATMC_AUDIT", 1);
dbObject.put("EVNTATMC_REMARKS", "First insert");
eventAtomic.insert(dbObject);
dbObject = new BasicDBObject();
dbObject.put("EVNTATMC_ID", new ObjectId());
dbObject.put("EVNTATMC_DESC", "1857 Revolt");
dbObject.put("EVNTATMC_FROM_TIME", "1857");
dbObject.put("EVNTATMC_TO_TIME", "1858");
dbObject.put("EVNTATMC_EVNTCMPD_ID", new ObjectId());
dbObject.put("EVNTATMC_MTRL_ID", null);
// dbObject.put("EVNTATMC_AUDIT", 1);
dbObject.put("EVNTATMC_REMARKS", "Only years");
eventAtomic.insert(dbObject);
Here, I dumbly used String to store incomplete dates but how should I store just an year like 1992, 2001, 2012 or just a month like January, September or something like August 2010 ? I'm not sure as to whether I'm expecting the correct thing ! Please guide me as to how I must handle such 'incomplete' timings.
***1st Edit ends here
Store the FROM_TIME and TO_TIME as DateTime. See Here: http://www.mongodb.org/display/DOCS/Dates
Then, you can query (rang query for example)
see the answer here:
https://stackoverflow.com/a/8136834/131809
So, for all events on August 15th 2012:
var start = new Date(2012, 08, 15);
var end = new Date(2012, 08, 16);
db.myEventCollection.find({created_on: {$gte: start, $lt: end}});