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 :
- {FROM_TIME : "September 1,1939", TO_TIME : "August 1945"}
- {FROM_TIME : "August 15,1947", TO_TIME : "August 15,1947"}
- {FROM_TIME : "1857", TO_TIME : "1858"}
- {FROM_TIME : "December 7,1944 11:00", TO_TIME : "December 7,1944 14:40"}
- {FROM_TIME : "January 1971", TO_TIME : "November 1972"}
Given the random occurrence of the FROM_TIME and TO_TIME, will it be possible to query for events like :
- List of events in the second half of the 19th century
- List of events on August 15
and so on.
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